Skip to content

Commit

Permalink
Add **kwargs to IOLoop initializers.
Browse files Browse the repository at this point in the history
This makes them compatible with the new make_current argument.

Add additional delay in test_streaming_until_close_future
for compatibility with AsyncIOLoop.
  • Loading branch information
bdarnell committed Apr 18, 2015
1 parent 3eb4e9f commit 838e1cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions tornado/ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,10 @@ def start(self):
# IOLoop is just started once at the beginning.
signal.set_wakeup_fd(old_wakeup_fd)
old_wakeup_fd = None
except ValueError: # non-main thread
pass
except ValueError:
# Non-main thread, or the previous value of wakeup_fd
# is no longer valid.
old_wakeup_fd = None

try:
while True:
Expand Down
11 changes: 6 additions & 5 deletions tornado/platform/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@


class BaseAsyncIOLoop(IOLoop):
def initialize(self, asyncio_loop, close_loop=False):
def initialize(self, asyncio_loop, close_loop=False, **kwargs):
super(BaseAsyncIOLoop, self).initialize(**kwargs)
self.asyncio_loop = asyncio_loop
self.close_loop = close_loop
self.asyncio_loop.call_soon(self.make_current)
Expand Down Expand Up @@ -132,15 +133,15 @@ def add_callback(self, callback, *args, **kwargs):


class AsyncIOMainLoop(BaseAsyncIOLoop):
def initialize(self):
def initialize(self, **kwargs):
super(AsyncIOMainLoop, self).initialize(asyncio.get_event_loop(),
close_loop=False)
close_loop=False, **kwargs)


class AsyncIOLoop(BaseAsyncIOLoop):
def initialize(self):
def initialize(self, **kwargs):
super(AsyncIOLoop, self).initialize(asyncio.new_event_loop(),
close_loop=True)
close_loop=True, **kwargs)


def to_tornado_future(asyncio_future):
Expand Down
3 changes: 2 additions & 1 deletion tornado/platform/twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ class TwistedIOLoop(tornado.ioloop.IOLoop):
because the ``SIGCHLD`` handlers used by Tornado and Twisted conflict
with each other.
"""
def initialize(self, reactor=None):
def initialize(self, reactor=None, **kwargs):
super(TwistedIOLoop, self).initialize(**kwargs)
if reactor is None:
import twisted.internet.reactor
reactor = twisted.internet.reactor
Expand Down
2 changes: 1 addition & 1 deletion tornado/test/iostream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def client_task():
@gen.coroutine
def server_task():
yield server.write(b"1234")
yield gen.moment
yield gen.sleep(0.01)
yield server.write(b"5678")
server.close()

Expand Down
4 changes: 2 additions & 2 deletions tornado/test/twisted_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,13 @@ class LayeredTwistedIOLoop(TwistedIOLoop):
correctly. In some tests another TornadoReactor is layered on top
of the whole stack.
"""
def initialize(self):
def initialize(self, **kwargs):
# When configured to use LayeredTwistedIOLoop we can't easily
# get the next-best IOLoop implementation, so use the lowest common
# denominator.
self.real_io_loop = SelectIOLoop()
reactor = TornadoReactor(io_loop=self.real_io_loop)
super(LayeredTwistedIOLoop, self).initialize(reactor=reactor)
super(LayeredTwistedIOLoop, self).initialize(reactor=reactor, **kwargs)
self.add_callback(self.make_current)

def close(self, all_fds=False):
Expand Down

0 comments on commit 838e1cf

Please sign in to comment.