From: Ben Darnell Date: Sun, 12 Jun 2016 17:41:20 +0000 (-0400) Subject: Allow any yieldable in with_timeout X-Git-Tag: v4.4.0b1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a48f65a42c3b3f0f2b21bcbce4da12c2d4419915;p=thirdparty%2Ftornado.git Allow any yieldable in with_timeout --- diff --git a/tornado/gen.py b/tornado/gen.py index 7ed8ba877..447ab5272 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -852,7 +852,7 @@ def with_timeout(timeout, future, io_loop=None, quiet_exceptions=()): Added the ``quiet_exceptions`` argument and the logging of unhandled exceptions. """ - # TODO: allow yield points in addition to futures? + # TODO: allow YieldPoints in addition to other yieldables? # Tricky to do with stack_context semantics. # # It's tempting to optimize this by cancelling the input future on timeout @@ -860,6 +860,7 @@ def with_timeout(timeout, future, io_loop=None, quiet_exceptions=()): # one waiting on the input future, so cancelling it might disrupt other # callers and B) concurrent futures can only be cancelled while they are # in the queue, so cancellation cannot reliably bound our waiting time. + future = convert_yielded(future) result = Future() chain_future(future, result) if io_loop is None: diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 1b118f948..4c873f4b5 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -767,6 +767,19 @@ class GenCoroutineTest(AsyncTestCase): self.assertEqual(results, [42, 43]) self.finished = True + @skipBefore35 + @gen_test + def test_async_with_timeout(self): + namespace = exec_test(globals(), locals(), """ + async def f1(): + return 42 + """) + + result = yield gen.with_timeout(datetime.timedelta(hours=1), + namespace['f1']()) + self.assertEqual(result, 42) + self.finished = True + @gen_test def test_sync_return_no_value(self): @gen.coroutine