Skip to content

Instantly share code, notes, and snippets.

@aglyzov
Last active December 17, 2015 09:18
Show Gist options
  • Save aglyzov/5585806 to your computer and use it in GitHub Desktop.
Save aglyzov/5585806 to your computer and use it in GitHub Desktop.
Illustrating a bug (?) in tornado 3.0.1 when fetching a firewalled https url -- a Timeout exception cannot be caught in the calling coroutine.
#!/usr/bin/env python3.3
from logging import getLogger
from tornado.ioloop import IOLoop
from tornado.options import parse_command_line
from tornado.httpclient import AsyncHTTPClient
from tornado.httputil import HTTPHeaders
from tornado.gen import coroutine
log = getLogger('tornado.application')
loop = IOLoop.instance()
@coroutine
def fetch_firewalled_url():
log.info('fetching a badly firewalled url')
http = AsyncHTTPClient()
try:
res = yield http.fetch(
'https://mtgox.com',
request_timeout = 5,
#headers = HTTPHeaders({'User-Agent':'Mozilla 5.0'})
)
err = res.error
except Exception as exc:
err = exc
if err:
log.error('error has been caught, OK')
log.error(err)
else:
log.info('there was no error, OK')
if __name__ == '__main__':
parse_command_line()
loop.run_sync(fetch_firewalled_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment