Skip to content

Commit 0535f2f

Browse files
committed
doc: document the pool parameter in decorators
Signed-off-by: Matteo Cafasso <[email protected]>
1 parent 56eeb04 commit 0535f2f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/index.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Pebble aims to help managing threads and processes in an easier way. It wraps Py
3333

3434
The *context* parameter can be used to specify the multiprocessing.context_ object used for starting the process.
3535

36+
The *pool* parameter accepts a pebble.ProcessPool_ object. If provided, the pool will be used to run the function instead of a dedicated process. The *name*, *daemon* and *context* parameters will be ignored.
37+
3638
.. decorator:: concurrent.thread(name=None, daemon=True)
3739

3840
Runs the decorated function in a concurrent thread, taking care of the results and error management.
@@ -43,6 +45,7 @@ Pebble aims to help managing threads and processes in an easier way. It wraps Py
4345

4446
The *daemon* parameter switches between daemon and non-daemon threads.
4547

48+
The *pool* parameter accepts a pebble.ThreadPool_ object. If provided, the pool will be used to run the function instead of a dedicated thread. The *name* and *daemon* parameters will be ignored.
4649

4750
`Asynchronous Module`
4851
---------------------
@@ -61,6 +64,8 @@ Pebble aims to help managing threads and processes in an easier way. It wraps Py
6164

6265
The *context* parameter can be used to specify the multiprocessing.context_ object used for starting the process.
6366

67+
The *pool* parameter accepts a pebble.ProcessPool_ object. If provided, the pool will be used to run the function instead of a dedicated process. The *name*, *daemon* and *context* parameters will be ignored.
68+
6469
.. decorator:: asynchronous.thread(name=None, daemon=True)
6570

6671
Runs the decorated function in a concurrent thread, taking care of the results and error management.
@@ -71,6 +76,8 @@ Pebble aims to help managing threads and processes in an easier way. It wraps Py
7176

7277
The *daemon* parameter switches between daemon and non-daemon threads.
7378

79+
The *pool* parameter accepts a pebble.ThreadPool_ object. If provided, the pool will be used to run the function instead of a dedicated thread. The *name* and *daemon* parameters will be ignored.
80+
7481

7582
`Pebble Module`
7683
---------------
@@ -474,6 +481,27 @@ If a `timeout` is provided, it will be applied to the whole chunk and not to the
474481

475482
assert list(future.result()) == elements
476483

484+
The `concurrent` and `asynchronous` decorators accept a *pool* parameter. This is useful to control how many instances of decorated functions can be run at the same time.
485+
486+
::
487+
488+
from concurrent.futures import wait
489+
from pebble import concurrent, ProcessPool
490+
491+
pool = ProcessPool(max_workers=4)
492+
493+
@concurrent.process(pool=pool)
494+
def function(arg, kwarg=0):
495+
return arg + kwarg
496+
497+
futures = []
498+
499+
# Maximum 4 executions of `function` will be executed in parallel
500+
for _ in range(100):
501+
futures.append(function(1, kwarg=1))
502+
503+
wait(futures)
504+
477505

478506
Pools and AsyncIO
479507
+++++++++++++++++

0 commit comments

Comments
 (0)