]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow any yieldable in with_timeout
authorBen Darnell <ben@bendarnell.com>
Sun, 12 Jun 2016 17:41:20 +0000 (13:41 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 12 Jun 2016 17:41:20 +0000 (13:41 -0400)
tornado/gen.py
tornado/test/gen_test.py

index 7ed8ba87707771a176090ccb99a590efb156078f..447ab52724f7d348433e2dce393c3212afc0d768 100644 (file)
@@ -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:
index 1b118f94888dbb4b6374b5d7d9b3ab8ad0b88922..4c873f4b5a580b0d68bfdce4ec7e48148caf56e4 100644 (file)
@@ -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