gevent.pool
– Managing greenlets in a group¶The Group
class in this module abstracts a group of running
greenlets. When a greenlet dies, it’s automatically removed from the
group. All running greenlets in a group can be waited on with
Group.joinall()
, or all running greenlets can be killed with
Group.kill()
.
The Pool
class, which is a subclass of Group
,
provides a way to limit concurrency: its spawn
method blocks if the number of greenlets in the pool has already
reached the limit, until there is a free slot.
Group
(*args)¶Bases: gevent.pool.GroupMappingMixin
Maintain a group of greenlets that are still running.
Links to each item and removes it upon notification.
greenlet_class
¶alias of Greenlet
add
(greenlet)¶discard
(greenlet)¶start
(greenlet)¶Start the un-started greenlet and add it to the collection of greenlets this group is monitoring.
spawn
(*args, **kwargs)¶Begin a new greenlet with the given arguments (which are passed to the greenlet constructor) and add it to the collection of greenlets this group is monitoring.
Returns: | The newly started greenlet. |
---|
join
(timeout=None, raise_error=False)¶kill
(exception=<class 'greenlet.GreenletExit'>, block=True, timeout=None)¶killone
(greenlet, exception=<class 'greenlet.GreenletExit'>, block=True, timeout=None)¶full
()¶wait_available
()¶Pool
(size=None, greenlet_class=None)¶Bases: gevent.pool.Group
Create a new pool.
A pool is like a group, but the maximum number of members is governed by the size parameter.
Parameters: | size (int) – If given, this non-negative integer is the maximum count of active greenlets that will be allowed in this pool. A few values have special significance:
|
---|
wait_available
(timeout=None)¶Wait until it’s possible to spawn a greenlet in this pool.
Parameters: | timeout (float) – If given, only wait the specified number of seconds. |
---|
Warning
If the pool was initialized with a size of 0, this method will block forever unless a timeout is given.
Returns: | A number indicating how many new greenlets can be put into the pool without blocking. |
---|
Changed in version 1.1a3: Added the timeout
parameter.
full
()¶Return a boolean indicating whether this pool has any room for members. (True if it does, False if it doesn’t.)
free_count
()¶Return a number indicating approximately how many more members can be added to this pool.
add
(greenlet)¶Next page: gevent.subprocess