From: Min RK Date: Wed, 31 Jan 2018 17:08:40 +0000 (+0100) Subject: fix gen.multi with gen.moment X-Git-Tag: v5.0.0~9^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4e652922553408ca0777127962f080724ce92c4;p=thirdparty%2Ftornado.git fix gen.multi with gen.moment 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 --- diff --git a/tornado/gen.py b/tornado/gen.py index 183b28f17..2b51c5f85 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -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) diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 6850af81c..f33ac3ca4 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -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()