summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorJosé Melero Fernández <jmelerofernandez@gmail.com>2018-01-25 23:45:43 (GMT)
committerYury Selivanov <yury@magic.io>2018-01-25 23:45:43 (GMT)
commitc47dacb69054f6fe1c2465df585985430f7fe366 (patch)
tree2c61c4eb401c8cdd863ef1db16efbba246a223ed /Lib/asyncio
parentc9070d03f5169ad6e171e641b7fa8feab18bf229 (diff)
downloadcpython-c47dacb69054f6fe1c2465df585985430f7fe366.zip
cpython-c47dacb69054f6fe1c2465df585985430f7fe366.tar.gz
cpython-c47dacb69054f6fe1c2465df585985430f7fe366.tar.bz2
bpo-32574: Fix leaks in asyncio.Queue.put() and .get() (#5208)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/queues.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py
index 512ea60..2a8d3e7 100644
--- a/Lib/asyncio/queues.py
+++ b/Lib/asyncio/queues.py
@@ -121,6 +121,13 @@ class Queue:
await putter
except:
putter.cancel() # Just in case putter is not done yet.
+ try:
+ # Clean self._putters from canceled putters.
+ self._putters.remove(putter)
+ except ValueError:
+ # The putter could be removed from self._putters by a
+ # previous get_nowait call.
+ pass
if not self.full() and not putter.cancelled():
# We were woken up by get_nowait(), but can't take
# the call. Wake up the next in line.
@@ -152,12 +159,13 @@ class Queue:
await getter
except:
getter.cancel() # Just in case getter is not done yet.
-
try:
+ # Clean self._getters from canceled getters.
self._getters.remove(getter)
except ValueError:
+ # The getter could be removed from self._getters by a
+ # previous put_nowait call.
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.