Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
15a528d4
Commit
15a528d4
authored
Aug 31, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #643 by using the right methods in Queue.peek; add test cases.
parent
65a18970
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
4 deletions
+18
-4
changelog.rst
changelog.rst
+2
-0
gevent/queue.py
gevent/queue.py
+2
-2
greentest/test__queue.py
greentest/test__queue.py
+14
-2
No files found.
changelog.rst
View file @
15a528d4
...
...
@@ -12,6 +12,8 @@
enabled with ``-O`` or ``PYTHONOPTIMIZE``. Previously these would go
undetected if optimizations were enabled, potentially leading to
erratic, difficult to debug behaviour.
- Fix an ``AttributeError`` from ``gevent.queue.Queue`` when ``peek``
was called on an empty ``Queue``. Reported in :issue:`643` by michaelvol.
1.1b3 (Aug 16, 2015)
====================
...
...
gevent/queue.py
View file @
15a528d4
...
...
@@ -298,7 +298,7 @@ class Queue(object):
waiter
=
Waiter
()
timeout
=
Timeout
.
start_new
(
timeout
,
Empty
)
try
:
self
.
getters
.
a
d
d
(
waiter
)
self
.
getters
.
a
ppen
d
(
waiter
)
if
self
.
putters
:
self
.
_schedule_unlock
()
result
=
waiter
.
get
()
...
...
@@ -306,7 +306,7 @@ class Queue(object):
raise
InvalidSwitchError
(
'Invalid switch into Queue.peek: %r'
%
(
result
,
))
return
self
.
_peek
()
finally
:
self
.
getters
.
discard
(
waiter
)
self
.
getters
.
remove
(
waiter
)
timeout
.
cancel
()
else
:
raise
Empty
...
...
greentest/test__queue.py
View file @
15a528d4
from
greentest
import
TestCase
,
main
,
GenericGetTestCase
import
gevent
from
gevent.hub
import
get_hub
from
gevent.hub
import
get_hub
,
LoopExit
from
gevent
import
util
from
gevent
import
queue
from
gevent.queue
import
Empty
,
Full
...
...
@@ -13,8 +13,20 @@ class TestQueue(TestCase):
self
.
switch_expected
=
False
q
=
queue
.
Queue
()
q
.
put
(
'hi'
)
self
.
assertEquals
(
q
.
peek
(),
'hi'
)
self
.
assertEquals
(
q
.
get
(),
'hi'
)
def
test_peek_empty
(
self
):
q
=
queue
.
Queue
()
# No putters waiting, in the main loop: LoopExit
self
.
assertRaises
(
LoopExit
,
q
.
peek
)
def
waiter
(
q
):
self
.
assertRaises
(
Empty
,
q
.
peek
,
timeout
=
0.01
)
g
=
gevent
.
spawn
(
waiter
,
q
)
gevent
.
sleep
(
0.1
)
g
.
join
()
def
test_send_last
(
self
):
q
=
queue
.
Queue
()
...
...
@@ -68,7 +80,7 @@ class TestQueue(TestCase):
p1
=
gevent
.
spawn
(
sender
,
e1
,
q
)
gevent
.
sleep
(
0.001
)
self
.
assert
_
(
not
e1
.
ready
())
self
.
assert
True
(
not
e1
.
ready
())
p2
=
gevent
.
spawn
(
receiver
,
e2
,
q
)
self
.
assertEquals
(
e2
.
get
(),
'hi'
)
self
.
assertEquals
(
e1
.
get
(),
'done'
)
...
...
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