diff --git a/mitterlib/network/__init__.py b/mitterlib/network/__init__.py index 3c3d5af..0b81f2a 100644 --- a/mitterlib/network/__init__.py +++ b/mitterlib/network/__init__.py @@ -151,6 +151,14 @@ class Networks(object): # add Networks own options self._options.add_group('Network_Manager', 'Network Manager') + self._options.add_option( + '--timeout', + group='Network_Manager', + option='timeout', + help='Timeout for requests in all networks.', + type='int', + metavar='SECONDS', + default=120) self._options.add_option( group='Network_Manager', option='save_count', diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 4855259..55a4022 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -219,9 +219,10 @@ class Connection(NetworkBase): _log.debug('Body: %s' % (body)) request.add_data(body) + timeout = self._options['Network_Manager']['timeout'] try: - _log.debug('Starting request of %s' % (url)) - response = urllib2.urlopen(request) + _log.debug('Starting request of %s (timeout %d)' % (url, timeout)) + response = urllib2.urlopen(request, timeout=timeout) data = response.read() except urllib2.HTTPError, exc: _log.debug('HTTPError: %d' % (exc.code)) diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index ed4d139..72ad22c 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -1242,8 +1242,9 @@ class Interface(object): def _download_pic(self, url): """Download a picture from the web. Can be used in a thread.""" request = urllib2.Request(url=url) - _log.debug('Starting request of %s' % (url)) - response = urllib2.urlopen(request) + timeout = self._options['Network_Manager']['timeout'] + _log.debug('Starting request of %s (timeout %d)' % (url, timeout)) + response = urllib2.urlopen(request, timeout=timeout) data = response.read() _log.debug('Request completed')