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
813fd8bf
Commit
813fd8bf
authored
Mar 16, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return whether the pool became empty in join.
Useful with a timeout argument. Fixes #503.
parent
71212515
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
11 deletions
+33
-11
changelog.rst
changelog.rst
+3
-0
gevent/pool.py
gevent/pool.py
+18
-10
greentest/test__pool.py
greentest/test__pool.py
+12
-1
No files found.
changelog.rst
View file @
813fd8bf
...
...
@@ -19,6 +19,9 @@
- Nested callbacks that set and clear an Event no longer cause
``wait`` to return prematurely. Reported in :issue:`771` by Sergey
Vasilyev.
- :class:`~.Group` and :class:`~.Pool` now return whether
:meth:`~.Group.join` returned with an empty group. Suggested by Filippo Sironi in
:pr:`503`.
1.1.0 (Mar 5, 2016)
===================
...
...
gevent/pool.py
View file @
813fd8bf
...
...
@@ -540,17 +540,25 @@ class Group(GroupMappingMixin):
one gets re-raised is not determined. Only greenlets currently
in the group when this method is called are guaranteed to
be checked for exceptions.
:return bool: A value indicating whether this group became empty.
If the timeout is specified and the group did not become empty
during that timeout, then this will be a false value. Otherwise
it will be a true value.
.. versionchanged:: 1.2a1
Add the return value.
"""
if
raise_error
:
greenlets
=
self
.
greenlets
.
copy
(
)
self
.
_empty_event
.
wait
(
timeout
=
timeout
)
for
greenlet
in
greenlets
:
if
greenlet
.
exception
is
not
None
:
if
hasattr
(
greenlet
,
'_raise_exception'
):
greenlet
.
_raise_exception
()
raise
greenlet
.
exception
else
:
self
.
_empty_event
.
wait
(
timeout
=
timeout
)
greenlets
=
list
(
self
.
greenlets
)
if
raise_error
else
()
result
=
self
.
_empty_event
.
wait
(
timeout
=
timeout
)
for
greenlet
in
greenlets
:
if
greenlet
.
exception
is
not
None
:
if
hasattr
(
greenlet
,
'_raise_exception'
):
greenlet
.
_raise_exception
()
raise
greenlet
.
exception
return
result
def
kill
(
self
,
exception
=
GreenletExit
,
block
=
True
,
timeout
=
None
):
"""
...
...
greentest/test__pool.py
View file @
813fd8bf
...
...
@@ -465,7 +465,8 @@ class TestJoinEmpty(greentest.TestCase):
def
test
(
self
):
p
=
pool
.
Pool
()
p
.
join
()
res
=
p
.
join
()
self
.
assertTrue
(
res
,
"empty should return true"
)
class
TestSpawn
(
greentest
.
TestCase
):
...
...
@@ -481,6 +482,16 @@ class TestSpawn(greentest.TestCase):
gevent
.
sleep
(
0.19
if
not
greentest
.
RUNNING_ON_APPVEYOR
else
0.5
)
self
.
assertEqual
(
len
(
p
),
0
)
def
testSpawnAndWait
(
self
):
p
=
pool
.
Pool
(
1
)
self
.
assertEqual
(
len
(
p
),
0
)
p
.
spawn
(
gevent
.
sleep
,
0.1
)
self
.
assertEqual
(
len
(
p
),
1
)
res
=
p
.
join
(
0.01
)
self
.
assertFalse
(
res
,
"waiting on a full pool should return false"
)
res
=
p
.
join
()
self
.
assertTrue
(
res
,
"waiting to finish should be true"
)
self
.
assertEqual
(
len
(
p
),
0
)
def
error_iter
():
yield
1
...
...
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