← 输入框|github.com|刷新
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
e3b23c2
Initial commit
YvesDup Mar 15, 2021
bc3d17a
make patchcheck
YvesDup Mar 15, 2021
a8b7b1a
make patchcheck
YvesDup Mar 15, 2021
32cbefb
Update test_locks.py
YvesDup Mar 16, 2021
e5002bc
Update locks.py
YvesDup Mar 16, 2021
b12599c
Update test_locks.py
YvesDup Mar 16, 2021
f12123e
Update from patch
YvesDup Mar 16, 2021
9ef7109
remove cpython/doc/*.rst.bak
YvesDup Mar 31, 2021
7b65fbc
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 31, 2021
9b60d07
Update 2021-03-31-15-22-45.bpo-43352.nSjMuE.rst
YvesDup Apr 2, 2021
576cd53
Update documentation about add of Barrier object
YvesDup Apr 11, 2021
6106f21
Update asyncio-sync.rst
YvesDup Apr 30, 2021
0384561
Update locks.py
YvesDup May 17, 2021
16515ef
Update test_locks.py
YvesDup May 17, 2021
fa217fd
Update asyncio-sync.rst
YvesDup May 17, 2021
a97f4a3
Update asyncio-sync.rst
YvesDup May 17, 2021
b598470
Update asyncio-sync.rst
YvesDup May 18, 2021
3098105
bpo-43352: Add a Barrier object to asyncio synchronized primitives (G…
YvesDup May 19, 2021
2f55acc
bpo-43352: Add a Barrier object to asyncio synchronized primitives (G…
YvesDup May 19, 2021
f056865
bpo-43352: Add a Barrier object to asyncio synchronized primitives (G…
YvesDup May 19, 2021
d9008f9
bpo-43352: Add a Barrier object to asyncio synchronized primitives (G…
YvesDup May 19, 2021
71b923c
bpo-43352: Add a Barrier object to asyncio synchronized primitives (G…
YvesDup May 19, 2021
6cf9ba8
Merge branch 'main' of https://github.com/YvesDup/cpython
YvesDup Apr 3, 2022
19c2c46
Merge branch 'python:main' into main
YvesDup Apr 3, 2022
3f4995c
Merge branch 'python:main' into main
YvesDup Apr 4, 2022
c98ee98
Merge branch 'python:main' into main
YvesDup Apr 6, 2022
05217c3
Merge branch 'python:main' into main
YvesDup Apr 8, 2022
f90d81c
Merge branch 'python:main' into main
YvesDup Apr 10, 2022
667433a
Merge branch 'python:main' into main
YvesDup Apr 13, 2022
aa01d9a
Merge branch 'python:main' into main
YvesDup Apr 15, 2022
8bc0df1
Merge branch 'python:main' into main
YvesDup Apr 19, 2022
51b1420
Merge branch 'python:main' into main
YvesDup Apr 19, 2022
e5bb0f1
Update test_locks.py
YvesDup Apr 19, 2022
31103dc
Merge branch 'python:main' into main
YvesDup Apr 27, 2022
45ef59d
Merge branch 'python:main' into main
YvesDup May 4, 2022
f89f389
Merge branch 'python:main' into main
YvesDup May 5, 2022
285af69
Merge branch 'python:main' into main
YvesDup May 8, 2022
1e48234
Merge branch 'python:main' into main
YvesDup May 11, 2022
2d8c432
Merge branch 'python:main' into main
YvesDup May 12, 2022
087b04f
Merge branch 'python:main' into main
YvesDup May 19, 2022
74a2fd2
Merge branch 'python:main' into main
YvesDup May 23, 2022
b2d6bda
Merge branch 'python:main' into main
YvesDup May 30, 2022
ce6b41b
Merge branch 'python:main' into main
YvesDup Jun 2, 2022
75ed38f
Merge branch 'python:main' into main
YvesDup Jun 7, 2022
aa3cc16
Merge branch 'python:main' into main
YvesDup Jun 9, 2022
37c6e49
Merge branch 'python:main' into main
YvesDup Jun 17, 2022
d0cb077
Merge branch 'python:main' into main
YvesDup Jun 27, 2022
4f59c48
Merge branch 'python:main' into main
YvesDup Jul 2, 2022
062571e
Merge branch 'python:main' into main
YvesDup Jul 8, 2022
8c87c8b
Merge branch 'python:main' into main
YvesDup Jul 11, 2022
67ed6be
Merge branch 'python:main' into main
YvesDup Jul 19, 2022
551699f
Merge branch 'python:main' into main
YvesDup Jul 25, 2022
f2d6a76
Merge branch 'python:main' into main
YvesDup Jul 26, 2022
04a1a19
Merge branch 'python:main' into main
YvesDup Jul 27, 2022
77000e4
Merge branch 'python:main' into main
YvesDup Aug 1, 2022
f20b7a8
Merge branch 'python:main' into main
YvesDup Aug 2, 2022
a07efda
Merge branch 'python:main' into main
YvesDup Aug 8, 2022
3706add
Merge branch 'python:main' into main
YvesDup Aug 12, 2022
40a1572
Merge branch 'python:main' into main
YvesDup Aug 17, 2022
c14abaa
Merge branch 'python:main' into main
YvesDup Aug 18, 2022
17a1da9
Merge branch 'python:main' into main
YvesDup Aug 22, 2022
bcac066
Merge branch 'python:main' into main
YvesDup Aug 22, 2022
1e199fc
Merge branch 'python:main' into main
YvesDup Aug 23, 2022
dff12bd
Merge branch 'python:main' into main
YvesDup Aug 24, 2022
b89329b
Merge branch 'python:main' into main
YvesDup Aug 27, 2022
ec376f1
Merge branch 'python:main' into main
YvesDup Aug 31, 2022
cb0f201
Merge branch 'python:main' into main
YvesDup Sep 2, 2022
47144ee
Merge branch 'python:main' into main
YvesDup Sep 4, 2022
4c417ed
Merge branch 'python:main' into main
YvesDup Sep 6, 2022
b451d32
Merge branch 'python:main' into main
YvesDup Sep 7, 2022
e320e46
Merge branch 'python:main' into main
YvesDup Sep 8, 2022
2b0cd71
Merge branch 'python:main' into main
YvesDup Sep 13, 2022
125366a
Merge branch 'python:main' into main
YvesDup Sep 14, 2022
8e4ee42
Merge branch 'python:main' into main
YvesDup Sep 17, 2022
fb7008e
Merge branch 'python:main' into main
YvesDup Sep 21, 2022
a343320
Merge branch 'python:main' into main
YvesDup Sep 29, 2022
8a689a7
Merge branch 'python:main' into main
YvesDup Oct 2, 2022
bd84883
Merge branch 'python:main' into main
YvesDup Oct 5, 2022
12f6307
Merge branch 'python:main' into main
YvesDup Oct 9, 2022
24fad09
Merge branch 'python:main' into main
YvesDup Oct 12, 2022
8eaeb11
Merge branch 'python:main' into main
YvesDup Dec 7, 2022
0823891
Merge branch 'python:main' into main
YvesDup Dec 19, 2022
282437e
Merge branch 'python:main' into main
YvesDup Jan 11, 2023
a23c8b8
Merge branch 'python:main' into main
YvesDup Jan 26, 2023
4075552
Merge branch 'python:main' into main
YvesDup Feb 4, 2023
526f11d
Merge branch 'python:main' into main
YvesDup May 10, 2023
7585c16
Merge branch 'python:main' into main
YvesDup Jun 10, 2023
255ccaa
Merge branch 'python:main' into main
YvesDup Jul 17, 2023
608d88d
Merge branch 'python:main' into main
YvesDup Jul 17, 2023
bba3418
Merge branch 'python:main' into main
YvesDup Nov 20, 2023
52d5caf
initial commit
YvesDup Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions Lib/asyncio/queues.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = ('Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty')
__all__ = ('Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty',
'QueueFullWithPendingPutTasks', 'QueueEmptyWithPendingGetTasks')

import collections
import heapq
Expand All @@ -12,11 +13,17 @@ class QueueEmpty(Exception):
"""Raised when Queue.get_nowait() is called on an empty Queue."""
pass

class QueueEmptyWithPendingGetTasks(QueueEmpty):
"""Raised when the Queue.get_nowait() method is called on not empty Queue._getters"""
pass

class QueueFull(Exception):
"""Raised when the Queue.put_nowait() method is called on a full Queue."""
pass

class QueueFullWithPendingPutTasks(QueueFull):
"""Raised when the Queue.put_nowait() method is called on not empty Queue._putters"""
pass

class Queue(mixins._LoopBoundMixin):
"""A queue, useful for coordinating producer and consumer coroutines.
Expand Down Expand Up @@ -57,8 +64,9 @@ def _put(self, item):

def _wakeup_next(self, waiters):
# Wake up the next waiter (if any) that isn't cancelled.
while waiters:
waiter = waiters.popleft()
# from gh-83055: don't remove future from waiters,
# do it in get() or put() when `waiter` wake up.
for waiter in waiters:
if not waiter.done():
waiter.set_result(None)
break
Expand Down Expand Up @@ -111,13 +119,16 @@ async def put(self, item):
"""Put an item into the queue.

Put an item into the queue. If the queue is full, wait until a free
slot is available before adding item.
slot is available before adding item. If there are still item moving
to a free or waiting for free slots, wait for its time.
"""
while self.full():
if self.full() or self._putters:
putter = self._get_loop().create_future()
self._putters.append(putter)
try:
await putter
# see gh-83055, clean self._putters.
self._putters.remove(putter)
except:
putter.cancel() # Just in case putter is not done yet.
try:
Expand All @@ -132,15 +143,26 @@ async def put(self, item):
# the call. Wake up the next in line.
self._wakeup_next(self._putters)
raise
return self.put_nowait(item)
# Don't run tests from self._put_nowait().
return self._put_and_wakeup_next(item)

def put_nowait(self, item):
"""Put an item into the queue without blocking.

If no free slot is immediately available, raise QueueFull.
If there are pending put tasks, raise QueueFullWithPendingPutTasks.
"""
if self.full():
raise QueueFull
if self._putters:
raise QueueFullWithPendingPutTasks
self._put_and_wakeup_next(item)

def _put_and_wakeup_next(self, item):
"""Put an item into the queue.

Wakes up next tasks waiting for slots.
"""
self._put(item)
self._unfinished_tasks += 1
self._finished.clear()
Expand All @@ -150,12 +172,16 @@ async def get(self):
"""Remove and return an item from the queue.

If queue is empty, wait until an item is available.
If queue is not empty and there are still tasks waiting for items,
task has to wait for its time.
"""
while self.empty():
if self.empty() or self._getters:
getter = self._get_loop().create_future()
self._getters.append(getter)
try:
await getter
# see gh-83055, clean self._getters.
self._getters.remove(getter)
except:
getter.cancel() # Just in case getter is not done yet.
try:
Expand All @@ -170,15 +196,26 @@ async def get(self):
# the call. Wake up the next in line.
self._wakeup_next(self._getters)
raise
return self.get_nowait()
# Don't run tests from self._get_nowait().
return self._get_and_wakeup_next()

def get_nowait(self):
"""Remove and return an item from the queue.

Return an item if one is immediately available, else raise QueueEmpty.
Return an item if one is immediately available, else raise QueueEmpty
Return an item if there is no pending get task, else raise QueueEmptyWithPendingGetTasks
"""
if self.empty():
raise QueueEmpty
if self._getters:
raise QueueEmptyWithPendingGetTasks
return self._get_and_wakeup_next()

def _get_and_wakeup_next(self):
"""Remove and return an item from the queue.

Wakes up next tasks waiting for slots.
"""
item = self._get()
self._wakeup_next(self._putters)
return item
Expand Down
Loading