Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #124 from bergundy/master

fixed add_timeout deadline in TornadoConnection added support for custom ioloop (for tornado testing)
  • Loading branch information...
commit 85d1d9184287c641db848a43642bd5d1aaa0d651 2 parents 85bf8fc + fa4173c
Gavin M. Roy authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 pika/adapters/tornado_connection.py
View
21 pika/adapters/tornado_connection.py
@@ -9,8 +9,6 @@
except ImportError:
IOLoop = None
-from warnings import warn
-
from pika.adapters.base_connection import BaseConnection
from pika.exceptions import AMQPConnectionError
from pika.reconnection_strategies import NullReconnectionStrategy
@@ -21,13 +19,15 @@
READ = ioloop.IOLoop.READ
WRITE = ioloop.IOLoop.WRITE
+import time
class TornadoConnection(BaseConnection):
def __init__(self, parameters=None,
on_open_callback=None,
reconnection_strategy=None,
- callback_interval=250):
+ callback_interval=250,
+ io_loop=None):
# Validate we have Tornado installed
if not IOLoop:
@@ -35,6 +35,7 @@ def __init__(self, parameters=None,
self.callback_interval = callback_interval
self._pc = None
+ self._default_ioloop = io_loop or IOLoop.instance()
BaseConnection.__init__(self, parameters, on_open_callback,
reconnection_strategy)
@@ -45,7 +46,7 @@ def _adapter_connect(self):
"""
# Setup our ioloop
if self.ioloop is None:
- self.ioloop = IOLoop.instance()
+ self.ioloop = self._default_ioloop
# Setup a periodic callbacks
if self._pc is None:
@@ -97,4 +98,14 @@ def stop_poller(self):
self._pc.stop()
# Remove from the IOLoop
- self.ioloop.remove_handler(self.socket.fileno())
+ self.ioloop.remove_handler(self.socket.fileno())
+
+ def add_timeout(self, deadline, callback):
+ """
+ Adds a timeout that will be called in `deadline` seconds.
+ Not to be confused with tornado.ioloop.add_timeout()
+ which accepts a timestamp or timedelta as the `deadline` argument.
+ """
+ # This override is required for the API
+ # to be consistent with other Connection classes
+ return self.ioloop.add_timeout(time.time() + deadline, callback)

0 comments on commit 85d1d91

Please sign in to comment.
Something went wrong with that request. Please try again.