Browse Source

Timeout in requests. fixes #89

master
Julio Biason 15 years ago
parent
commit
86c3c9eae5
  1. 8
      mitterlib/network/__init__.py
  2. 5
      mitterlib/network/twitter.py
  3. 5
      mitterlib/ui/ui_pygtk.py

8
mitterlib/network/__init__.py

@ -151,6 +151,14 @@ class Networks(object):
# add Networks own options # add Networks own options
self._options.add_group('Network_Manager', 'Network Manager') 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( self._options.add_option(
group='Network_Manager', group='Network_Manager',
option='save_count', option='save_count',

5
mitterlib/network/twitter.py

@ -219,9 +219,10 @@ class Connection(NetworkBase):
_log.debug('Body: %s' % (body)) _log.debug('Body: %s' % (body))
request.add_data(body) request.add_data(body)
timeout = self._options['Network_Manager']['timeout']
try: try:
_log.debug('Starting request of %s' % (url)) _log.debug('Starting request of %s (timeout %d)' % (url, timeout))
response = urllib2.urlopen(request) response = urllib2.urlopen(request, timeout=timeout)
data = response.read() data = response.read()
except urllib2.HTTPError, exc: except urllib2.HTTPError, exc:
_log.debug('HTTPError: %d' % (exc.code)) _log.debug('HTTPError: %d' % (exc.code))

5
mitterlib/ui/ui_pygtk.py

@ -1242,8 +1242,9 @@ class Interface(object):
def _download_pic(self, url): def _download_pic(self, url):
"""Download a picture from the web. Can be used in a thread.""" """Download a picture from the web. Can be used in a thread."""
request = urllib2.Request(url=url) request = urllib2.Request(url=url)
_log.debug('Starting request of %s' % (url)) timeout = self._options['Network_Manager']['timeout']
response = urllib2.urlopen(request) _log.debug('Starting request of %s (timeout %d)' % (url, timeout))
response = urllib2.urlopen(request, timeout=timeout)
data = response.read() data = response.read()
_log.debug('Request completed') _log.debug('Request completed')

Loading…
Cancel
Save