]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow the same future multiple times in `multi_future` 1412/head
authorAbhinav Gupta <abg@uber.com>
Tue, 7 Apr 2015 18:57:45 +0000 (11:57 -0700)
committerAbhinav Gupta <abg@uber.com>
Tue, 7 Apr 2015 18:57:45 +0000 (11:57 -0700)
This prevents failures in cases like the following:

    f = <some future>
    yield [f, f]

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

index 6eac483097b967c2038ca1ac612be893851047e4..e184c43371c44b6d946aa2edd52a61dc74ab983a 100644 (file)
@@ -671,8 +671,12 @@ def multi_future(children, quiet_exceptions=()):
                     future.set_result(dict(zip(keys, result_list)))
                 else:
                     future.set_result(result_list)
+
+    listening = set()
     for f in children:
-        f.add_done_callback(callback)
+        if f not in listening:
+            listening.add(f)
+            f.add_done_callback(callback)
     return future
 
 
index 53c89ace594e7d5036615817885734e7515ac8f6..d9188fec30dac9a33f8b749101966407a3d9073f 100644 (file)
@@ -390,6 +390,12 @@ class GenEngineTest(AsyncTestCase):
         results = yield [self.async_future(1), self.async_future(2)]
         self.assertEqual(results, [1, 2])
 
+    @gen_test
+    def test_multi_future_duplicate(self):
+        f = self.async_future(2)
+        results = yield [self.async_future(1), f, self.async_future(3), f]
+        self.assertEqual(results, [1, 2, 3, 2])
+
     @gen_test
     def test_multi_dict_future(self):
         results = yield dict(foo=self.async_future(1), bar=self.async_future(2))