diff options
author | David Cramer <dcramer@gmail.com> | 2012-06-27 22:51:50 -0700 |
---|---|---|
committer | David Cramer <dcramer@gmail.com> | 2012-06-27 22:51:50 -0700 |
commit | 68e0942fbbd2ba4e19b1288ba209f65d2178a1c8 (patch) | |
tree | fee3eb971e43dafd6e4abb7b2c51e652fcd6fb3e | |
parent | d973d4503c740b961c1d167a6bad8f2375e905fd (diff) | |
parent | a355a283ec6c5504c61afbd7918a12611fd35844 (diff) | |
download | raven-68e0942fbbd2ba4e19b1288ba209f65d2178a1c8.tar.gz |
Merge pull request #139 from faulkner/fix-tornado-ioloop
Fall back to synchronous HTTP client if Tornado ioloop isn't running.
-rw-r--r-- | raven/transport.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/raven/transport.py b/raven/transport.py index e7101fb..2b7e1e1 100644 --- a/raven/transport.py +++ b/raven/transport.py @@ -15,7 +15,8 @@ except: twisted = False try: - from tornado.httpclient import AsyncHTTPClient + from tornado import ioloop + from tornado.httpclient import AsyncHTTPClient, HTTPClient tornado = True except: tornado = False @@ -227,9 +228,16 @@ class TornadoHTTPTransport(HTTPTransport): self._url = self._url.split('+', 1)[-1] def send(self, data, headers): - client = AsyncHTTPClient() - client.fetch(self._url, callback=None, - method='POST', headers=headers, body=data) + kwargs = dict(method='POST', headers=headers, body=data) + + # only use async if ioloop is running, otherwise it will never send + if ioloop.IOLoop.initialized(): + client = AsyncHTTPClient() + kwargs['callback'] = None + else: + client = HTTPClient() + + client.fetch(self._url, **kwargs) class TransportRegistry(object): |