Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0bd16bc4
Commit
0bd16bc4
authored
Apr 20, 2015
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix asyncio issue 235: Queue subclass bug caused by JoinableQueue merge.
parent
77e8311d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
+36
-11
Lib/asyncio/queues.py
Lib/asyncio/queues.py
+13
-6
Lib/test/test_asyncio/test_queues.py
Lib/test/test_asyncio/test_queues.py
+19
-5
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/asyncio/queues.py
View file @
0bd16bc4
...
...
@@ -54,6 +54,8 @@ class Queue:
self
.
_finished
.
set
()
self
.
_init
(
maxsize
)
# These three are overridable in subclasses.
def
_init
(
self
,
maxsize
):
self
.
_queue
=
collections
.
deque
()
...
...
@@ -62,6 +64,11 @@ class Queue:
def
_put
(
self
,
item
):
self
.
_queue
.
append
(
item
)
# End of the overridable methods.
def
__put_internal
(
self
,
item
):
self
.
_put
(
item
)
self
.
_unfinished_tasks
+=
1
self
.
_finished
.
clear
()
...
...
@@ -133,7 +140,7 @@ class Queue:
'queue non-empty, why are getters waiting?'
)
getter
=
self
.
_getters
.
popleft
()
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
# getter cannot be cancelled, we just removed done getters
getter
.
set_result
(
self
.
_get
())
...
...
@@ -145,7 +152,7 @@ class Queue:
yield
from
waiter
else
:
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
def
put_nowait
(
self
,
item
):
"""Put an item into the queue without blocking.
...
...
@@ -158,7 +165,7 @@ class Queue:
'queue non-empty, why are getters waiting?'
)
getter
=
self
.
_getters
.
popleft
()
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
# getter cannot be cancelled, we just removed done getters
getter
.
set_result
(
self
.
_get
())
...
...
@@ -166,7 +173,7 @@ class Queue:
elif
self
.
_maxsize
>
0
and
self
.
_maxsize
<=
self
.
qsize
():
raise
QueueFull
else
:
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
@
coroutine
def
get
(
self
):
...
...
@@ -180,7 +187,7 @@ class Queue:
if
self
.
_putters
:
assert
self
.
full
(),
'queue not full, why are putters waiting?'
item
,
putter
=
self
.
_putters
.
popleft
()
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
# When a getter runs and frees up a slot so this putter can
# run, we need to defer the put for a tick to ensure that
...
...
@@ -207,7 +214,7 @@ class Queue:
if
self
.
_putters
:
assert
self
.
full
(),
'queue not full, why are putters waiting?'
item
,
putter
=
self
.
_putters
.
popleft
()
self
.
_
put
(
item
)
self
.
_
_put_internal
(
item
)
# Wake putter on next tick.
# getter cannot be cancelled, we just removed done putters
...
...
Lib/test/test_asyncio/test_queues.py
View file @
0bd16bc4
...
...
@@ -408,14 +408,16 @@ class PriorityQueueTests(_QueueTestBase):
self
.
assertEqual
([
1
,
2
,
3
],
items
)
class
QueueJoinTests
(
_QueueTestBase
):
class
_QueueJoinTestMixin
:
q_class
=
None
def
test_task_done_underflow
(
self
):
q
=
asyncio
.
Queue
(
loop
=
self
.
loop
)
q
=
self
.
q_class
(
loop
=
self
.
loop
)
self
.
assertRaises
(
ValueError
,
q
.
task_done
)
def
test_task_done
(
self
):
q
=
asyncio
.
Queue
(
loop
=
self
.
loop
)
q
=
self
.
q_class
(
loop
=
self
.
loop
)
for
i
in
range
(
100
):
q
.
put_nowait
(
i
)
...
...
@@ -452,7 +454,7 @@ class QueueJoinTests(_QueueTestBase):
self
.
loop
.
run_until_complete
(
asyncio
.
wait
(
tasks
,
loop
=
self
.
loop
))
def
test_join_empty_queue
(
self
):
q
=
asyncio
.
Queue
(
loop
=
self
.
loop
)
q
=
self
.
q_class
(
loop
=
self
.
loop
)
# Test that a queue join()s successfully, and before anything else
# (done twice for insurance).
...
...
@@ -465,12 +467,24 @@ class QueueJoinTests(_QueueTestBase):
self
.
loop
.
run_until_complete
(
join
())
def
test_format
(
self
):
q
=
asyncio
.
Queue
(
loop
=
self
.
loop
)
q
=
self
.
q_class
(
loop
=
self
.
loop
)
self
.
assertEqual
(
q
.
_format
(),
'maxsize=0'
)
q
.
_unfinished_tasks
=
2
self
.
assertEqual
(
q
.
_format
(),
'maxsize=0 tasks=2'
)
class
QueueJoinTests
(
_QueueJoinTestMixin
,
_QueueTestBase
):
q_class
=
asyncio
.
Queue
class
LifoQueueJoinTests
(
_QueueJoinTestMixin
,
_QueueTestBase
):
q_class
=
asyncio
.
LifoQueue
class
PriorityQueueJoinTests
(
_QueueJoinTestMixin
,
_QueueTestBase
):
q_class
=
asyncio
.
PriorityQueue
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
0bd16bc4
...
...
@@ -29,6 +29,10 @@ Core and Builtins
Library
-------
- Fix asyncio issue 235: LifoQueue and PriorityQueue'
s
put
didn
't
increment unfinished tasks (this bug was introduced in 3.4.3 when
JoinableQueue was merged with Queue).
- Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment