gevent.threadpool
- A pool of native threads¶ThreadPool
(maxsize, hub=None)¶Bases: gevent.pool.GroupMappingMixin
apply
(func, args=None, kwds=None)¶Rough equivalent of the apply()
builtin function,
blocking until the result is ready and returning it.
The func
will usually, but not always, be run in a way
that allows the current greenlet to switch out (for example,
in a new greenlet or thread, depending on implementation). But
if the current greenlet or thread is already one that was
spawned by this pool, the pool may choose to immediately run
the func synchronously.
Note
As implemented, attempting to use
Threadpool.appy()
from inside another function that
was itself spawned in a threadpool (any threadpool) will
cause the function to be run immediatesly.
join
()¶Waits until all outstanding tasks have been completed.
spawn
(func, *args, **kwargs)¶Add a new task to the threadpool that will run func(*args, **kwargs)
.
Waits until a slot is available. Creates a new thread if necessary.
Returns: | A gevent.event.AsyncResult . |
---|
apply_e
(expected_errors, function, args=None, kwargs=None)¶Deprecated since version 1.1a2: Identical to apply()
; the expected_errors
argument is ignored.
apply_async
(func, args=None, kwds=None, callback=None)¶A variant of the apply() method which returns a Greenlet object.
If callback is specified then it should be a callable which accepts a single argument. When the result becomes ready callback is applied to it (unless the call failed).
apply
(func, args=None, kwds=None)Rough quivalent of the apply()
builtin function blocking until
the result is ready and returning it.
The func
will usually, but not always, be run in a way
that allows the current greenlet to switch out (for example,
in a new greenlet or thread, depending on implementation). But
if the current greenlet or thread is already one that was
spawned by this pool, the pool may choose to immediately run
the func synchronously.
map
(func, iterable)¶Return a list made by applying the func to each element of the iterable.
See also
map_async
(func, iterable, callback=None)¶A variant of the map() method which returns a Greenlet object that is executing the map function.
If callback is specified then it should be a callable which accepts a single argument.
imap
(func, *iterables, maxsize=None) → iterable¶An equivalent of itertools.imap()
, operating in parallel.
The func is applied to each element yielded from each
iterable in iterables in turn, collecting the result.
If this object has a bound on the number of active greenlets it can
contain (such as Pool
), then at most that number of tasks will operate
in parallel.
Parameters: | maxsize (int) – If given and not-None, specifies the maximum number of finished results that will be allowed to accumulate awaiting the reader; more than that number of results will cause map function greenlets to begin to block. This is most useful is there is a great disparity in the speed of the mapping code and the consumer and the results consume a great deal of resources. Note This is separate from any bound on the number of active parallel tasks, though they may have some interaction (for example, limiting the number of parallel tasks to the smallest bound). Note Using a bound is slightly more computationally expensive than not using a bound. Tip The |
---|---|
Returns: | An iterable object. |
Changed in version 1.1b3: Added the maxsize keyword parameter.
imap_unordered
(func, *iterables, maxsize=None) → iterable¶The same as imap()
except that the ordering of the results
from the returned iterator should be considered in arbitrary
order.
This is lighter weight than imap()
and should be preferred if order
doesn’t matter.
See also
imap()
for more details.
Next page: Low-level details