[Python-checkins] bpo-31620: have asyncio/queues not leak memory when you've exceptions during waiting (GH-3813) (#4326)

Andrew Svetlov webhook-mailer at python.org
Tue Nov 7 14:08:18 EST 2017


https://github.com/python/cpython/commit/ac4f6d4448fb6f9affb817bafb8357450fe43349
commit: ac4f6d4448fb6f9affb817bafb8357450fe43349
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Andrew Svetlov <andrew.svetlov at gmail.com>
date: 2017年11月07日T22:08:15+03:00
summary:
bpo-31620: have asyncio/queues not leak memory when you've exceptions during waiting (GH-3813) (#4326)
(cherry picked from commit c62f0cb3b1f6f9ca4ce463b1c99b0543bdfa38d6)
files:
A Misc/NEWS.d/next/Library/2017-10-06-04-35-31.bpo-31620.gksLA1.rst
M Lib/asyncio/queues.py
M Lib/test/test_asyncio/test_queues.py
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
index 2d38972c0de..1c66d67b041 100644
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -167,6 +167,12 @@ def get(self):
 yield from getter
 except:
 getter.cancel() # Just in case getter is not done yet.
+
+ try:
+ self._getters.remove(getter)
+ except ValueError:
+ pass
+
 if not self.empty() and not getter.cancelled():
 # We were woken up by put_nowait(), but can't take
 # the call. Wake up the next in line.
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index fe5a6dbfe34..2137cde6f48 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -295,6 +295,23 @@ def producer(queue, num_items):
 loop=self.loop),
 )
 
+ def test_cancelled_getters_not_being_held_in_self_getters(self):
+ def a_generator():
+ yield 0.1
+ yield 0.2
+
+ self.loop = self.new_test_loop(a_generator)
+ @asyncio.coroutine
+ def consumer(queue):
+ try:
+ item = yield from asyncio.wait_for(queue.get(), 0.1, loop=self.loop)
+ except asyncio.TimeoutError:
+ pass
+
+ queue = asyncio.Queue(loop=self.loop, maxsize=5)
+ self.loop.run_until_complete(self.loop.create_task(consumer(queue)))
+ self.assertEqual(len(queue._getters), 0)
+
 
 class QueuePutTests(_QueueTestBase):
 
diff --git a/Misc/NEWS.d/next/Library/2017-10-06-04-35-31.bpo-31620.gksLA1.rst b/Misc/NEWS.d/next/Library/2017-10-06-04-35-31.bpo-31620.gksLA1.rst
new file mode 100644
index 00000000000..7874befaaa2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-06-04-35-31.bpo-31620.gksLA1.rst
@@ -0,0 +1,2 @@
+an empty asyncio.Queue now doesn't leak memory when queue.get pollers
+timeout


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /