]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
fix gen.multi with gen.moment
authorMin RK <benjaminrk@gmail.com>
Wed, 31 Jan 2018 17:08:40 +0000 (18:08 +0100)
committerMin RK <benjaminrk@gmail.com>
Wed, 31 Jan 2018 17:08:40 +0000 (18:08 +0100)
fixes assertion in gen.multi when calling convert_yielded with more than one gen.moment or None

convert_yielded can be called with None or [None].
When it is called with [None], gen.multi gets [gen.moment],
which fails assert(is_future) since it is no longer a real Future

tornado/gen.py
tornado/test/gen_test.py

index 183b28f17a173cc6edb0cbc1ba0ccfead1854c4b..2b51c5f856a47f5a1bbefe72b2fb7328e8ffbff2 100644 (file)
@@ -814,6 +814,9 @@ def multi_future(children, quiet_exceptions=()):
     else:
         keys = None
     children = list(map(convert_yielded, children))
+    # filter out NullFutures, like gen.moment
+    children = [child for child in children
+                if not isinstance(child, _NullFuture)]
     assert all(is_future(i) for i in children)
     unfinished_children = set(children)
 
index 6850af81c84d5949f98a5760a9461e641a06339e..f33ac3ca45130ccd337972243d4b9fdc03ab3fa2 100644 (file)
@@ -1598,6 +1598,16 @@ class RunnerGCTest(AsyncTestCase):
             # coroutine finalizer was called (not on PyPy3 apparently)
             self.assertIs(result[-1], None)
 
+    def test_multi_moment(self):
+        # Test gen.multi with moment
+        # now that it's not a real Future
+        @gen.coroutine
+        def wait_a_moment():
+            yield gen.multi([gen.moment, gen.moment])
+
+        loop = self.get_new_ioloop()
+        loop.run_sync(wait_a_moment)
+
 
 if __name__ == '__main__':
     unittest.main()