[Python-checkins] cpython (merge 3.4 -> 3.5): Merge 3.4 (issue #23812)

yury.selivanov python-checkins at python.org
Thu Aug 6 20:04:52 CEST 2015


https://hg.python.org/cpython/rev/2752fe734bfb
changeset:   97309:2752fe734bfb
branch:      3.5
parent:      97306:526a186de32d
parent:      97308:024d4f4011c9
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Thu Aug 06 14:04:12 2015 -0400
summary:
  Merge 3.4 (issue #23812)

files:
  Lib/asyncio/queues.py                |   2 +-
  Lib/test/test_asyncio/test_queues.py |  37 +++++++++++++++-
  2 files changed, 37 insertions(+), 2 deletions(-)


diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -228,7 +228,7 @@
                 'queue non-empty, why are getters waiting?')
 
             getter = self._getters.popleft()
-            self._put_internal(item)
+            self.__put_internal(item)
 
             # getter cannot be cancelled, we just removed done getters
             getter.set_result(item)
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -322,7 +322,7 @@
         q.put_nowait(1)
         self.assertEqual(1, q.get_nowait())
 
-    def test_get_cancel_drop(self):
+    def test_get_cancel_drop_one_pending_reader(self):
         def gen():
             yield 0.01
             yield 0.1
@@ -350,6 +350,41 @@
         # if we get 2, it means 1 got dropped!
         self.assertEqual(1, result)
 
+    def test_get_cancel_drop_many_pending_readers(self):
+        def gen():
+            yield 0.01
+            yield 0.1
+
+        loop = self.new_test_loop(gen)
+        loop.set_debug(True)
+
+        q = asyncio.Queue(loop=loop)
+
+        reader1 = loop.create_task(q.get())
+        reader2 = loop.create_task(q.get())
+        reader3 = loop.create_task(q.get())
+
+        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
+
+        q.put_nowait(1)
+        q.put_nowait(2)
+        reader1.cancel()
+
+        try:
+            loop.run_until_complete(reader1)
+        except asyncio.CancelledError:
+            pass
+
+        loop.run_until_complete(reader3)
+
+        # reader2 will receive `2`, because it was added to the
+        # queue of pending readers *before* put_nowaits were called.
+        self.assertEqual(reader2.result(), 2)
+        # reader3 will receive `1`, because reader1 was cancelled
+        # before is had a chance to execute, and `2` was already
+        # pushed to reader2 by second `put_nowait`.
+        self.assertEqual(reader3.result(), 1)
+
     def test_put_cancel_drop(self):
 
         def gen():

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list