You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89-15Lines changed: 89 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,49 @@
1
1
# asyncio-pool
2
2
3
-
###### Supports python 3.5+ (including PyPy 6+, which is also 3.5)
3
+
Pool of asyncio coroutines with familiar interface. Supports python 3.5+ (including PyPy 6+, which is also 3.5 atm)
4
+
5
+
AioPool makes sure _no more_ and _no less_ (if possible) than `size` spawned coroutines are active at the same time. _spawned_ means created and scheduled with one of the pool interface methods, _active_ means coroutine function started executing it's code, as opposed to _waiting_ -- which waits for pool space without entering coroutine function.
6
+
7
+
## Interface
8
+
9
+
Read [code doctrings](../blob/master/asyncio_pool/base_pool.py) for details.
10
+
11
+
##### AioPool(size=4, *, loop=None)
12
+
13
+
Creates pool of `size` concurrent tasks. Supports async context manager interface.
14
+
15
+
##### spawn(coro, cb=None, ctx=None)
16
+
17
+
Waits for pool space, then creates task for `coro` coroutine, returning future for it's result. Can spawn coroutine, created by `cb` with result of `coro` as first argument. `ctx` context is passed to callback as third positinal argument.
18
+
19
+
##### exec(coro, cb=None, ctx=None)
20
+
21
+
Waits for pool space, then creates task for `coro`, then waits for it to finish, then returns result of `coro` if no callback is provided, otherwise creates task for callback, waits for it and returns result of callback.
22
+
23
+
##### spawn_n(coro, cb=None, ctx=None)
24
+
25
+
Creates waiting task for `coro`, returns future without waiting for pool space. Task is executed "in pool" when pool space is available.
26
+
27
+
##### join()
28
+
29
+
Waits for all spawned (active and waiting) tasks to finish. Joining pool from coroutine, spawned by the same pool leads to *deadlock*.
30
+
31
+
##### cancel(*futures)
32
+
33
+
Cancels spawned tasks (active and waiting), finding them by provided `futures`. If no futures provided -- cancels all spawned tasks.
Spawns coroutines created by `fn` function for each item in `iterable` with `spawn`, waits for all of them to finish (including callbacks), returns results maintaining order of `iterable`.
Spawns coroutines created by `fn` function for each item in `iterable` with `spawn_n`, returns futures for task results maintaining order of `iterable`.
Spawns tasks with `map_n(fn, iterable, cb, ctx)`, then waits for results with `asyncio.wait` function, yielding ready results one by one if `flat` == True, otherwise yielding list of ready results.
46
+
4
47
5
48
6
49
## Usage
@@ -11,9 +54,11 @@
11
54
12
55
Play with `python tests/loadtest.py -h` to understand what you want to use.
13
56
14
-
#### Usage examples (more in `tests/` and `examples/` dirs):
57
+
Usage examples (more in `tests/` and `examples/` dirs):
0 commit comments