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
74b97b90
Commit
74b97b90
authored
Nov 08, 2017
by
Ron Rothman
Committed by
Jason Madden
Nov 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add blocking and timeout params to Pool.add
parent
387b4f3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
src/gevent/pool.py
src/gevent/pool.py
+27
-4
No files found.
src/gevent/pool.py
View file @
74b97b90
...
@@ -461,10 +461,13 @@ class Group(GroupMappingMixin):
...
@@ -461,10 +461,13 @@ class Group(GroupMappingMixin):
"""
"""
return
iter
(
self
.
greenlets
)
return
iter
(
self
.
greenlets
)
def
add
(
self
,
greenlet
):
def
add
(
self
,
greenlet
,
blocking
=
False
,
timeout
=
None
):
"""
"""
Begin tracking the greenlet.
Begin tracking the greenlet.
:keyword bool blocking: and :keyword bool timeout: are ignored
in this method; subclasses may use them (see :meth:`Pool.add`).
If this group is :meth:`full`, then this method may block
If this group is :meth:`full`, then this method may block
until it is possible to track the greenlet.
until it is possible to track the greenlet.
"""
"""
...
@@ -714,19 +717,39 @@ class Pool(Group):
...
@@ -714,19 +717,39 @@ class Pool(Group):
return
1
return
1
return
max
(
0
,
self
.
size
-
len
(
self
))
return
max
(
0
,
self
.
size
-
len
(
self
))
def
add
(
self
,
greenlet
):
def
add
(
self
,
greenlet
,
blocking
=
True
,
timeout
=
None
):
"""
"""
Begin tracking the given greenlet, blocking until space is available.
Begin tracking the given greenlet, possibly blocking until space is
available.
:keyword bool blocking: If True (the default), this function will block
until the pool has space or a timeout occurs.
:keyword float timeout: The maximum number of seconds this method will block.
:return: True if the greenlet was added; False if a Timeout occured or
if blocking is True and the pool is full.
.. seealso:: :meth:`Group.add`
.. seealso:: :meth:`Group.add`
"""
"""
self
.
_semaphore
.
acquire
()
try
:
# NOTE: The docs for Semaphore.acquire indicate that it may raise a Timeout rather
# than return False under some circumstances, though I'm not sure exactly what those
# circumstances are.
was_acquired
=
self
.
_semaphore
.
acquire
(
blocking
=
blocking
,
timeout
=
timeout
)
except
Timeout
:
was_acquired
=
False
if
not
was_acquired
:
return
False
try
:
try
:
Group
.
add
(
self
,
greenlet
)
Group
.
add
(
self
,
greenlet
)
except
:
except
:
self
.
_semaphore
.
release
()
self
.
_semaphore
.
release
()
raise
raise
return
True
def
_discard
(
self
,
greenlet
):
def
_discard
(
self
,
greenlet
):
Group
.
_discard
(
self
,
greenlet
)
Group
.
_discard
(
self
,
greenlet
)
self
.
_semaphore
.
release
()
self
.
_semaphore
.
release
()
...
...
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