aiomisc 17.7.1__py3-none-any.whl → 17.7.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiomisc/process_pool.py +56 -0
- aiomisc/version.py +2 -2
- {aiomisc-17.7.1.dist-info → aiomisc-17.7.3.dist-info}/METADATA +1 -1
- {aiomisc-17.7.1.dist-info → aiomisc-17.7.3.dist-info}/RECORD +7 -7
- {aiomisc-17.7.1.dist-info → aiomisc-17.7.3.dist-info}/COPYING +0 -0
- {aiomisc-17.7.1.dist-info → aiomisc-17.7.3.dist-info}/WHEEL +0 -0
- {aiomisc-17.7.1.dist-info → aiomisc-17.7.3.dist-info}/entry_points.txt +0 -0
aiomisc/process_pool.py
CHANGED
@@ -18,9 +18,59 @@ class ProcessPoolStatistic(Statistic):
|
|
18
18
|
|
19
19
|
|
20
20
|
class ProcessPoolExecutor(ProcessPoolExecutorBase, EventLoopMixin):
|
21
|
+
"""
|
22
|
+
Process pool executor with statistic
|
23
|
+
|
24
|
+
Usage:
|
25
|
+
|
26
|
+
.. code-block:: python
|
27
|
+
|
28
|
+
from time import sleep
|
29
|
+
from aiomisc import ProcessPoolExecutor
|
30
|
+
|
31
|
+
# NOTE: blocking function must be defined at the top level
|
32
|
+
# of the module to be able to be pickled and sent to the
|
33
|
+
# child processes.
|
34
|
+
def blocking_fn():
|
35
|
+
sleep(1)
|
36
|
+
return 42
|
37
|
+
|
38
|
+
async def main():
|
39
|
+
executor = ProcessPoolExecutor()
|
40
|
+
the_answer = await executor.submit(blocking_fn)
|
41
|
+
print("The answer is:", the_answer)
|
42
|
+
|
43
|
+
asyncio.run(main())
|
44
|
+
"""
|
45
|
+
|
21
46
|
DEFAULT_MAX_WORKERS = max((cpu_count(), 4))
|
22
47
|
|
23
48
|
def __init__(self, max_workers: int = DEFAULT_MAX_WORKERS, **kwargs: Any):
|
49
|
+
"""
|
50
|
+
Initializes a new ProcessPoolExecutor instance.
|
51
|
+
|
52
|
+
* ``max_workers``:
|
53
|
+
The maximum number of processes that can be used to
|
54
|
+
execute the given calls. If None or not given then
|
55
|
+
as many worker processes will be created as the
|
56
|
+
machine has processors.
|
57
|
+
* ``mp_context``:
|
58
|
+
A multiprocessing context to launch the workers. This
|
59
|
+
object should provide SimpleQueue, Queue and Process.
|
60
|
+
Useful to allow specific multiprocessing start methods.
|
61
|
+
* ``initializer``:
|
62
|
+
A callable used to initialize worker processes.
|
63
|
+
* ``initargs``:
|
64
|
+
A tuple of arguments to pass to the initializer.
|
65
|
+
* ``max_tasks_per_child``:
|
66
|
+
The maximum number of tasks a worker process
|
67
|
+
can complete before it will exit and be replaced
|
68
|
+
with a fresh worker process. The default of None
|
69
|
+
means worker process will live as long as the
|
70
|
+
executor. Requires a non-'fork' mp_context start
|
71
|
+
method. When given, we default to using 'spawn'
|
72
|
+
if no mp_context is supplied.
|
73
|
+
"""
|
24
74
|
super().__init__(max_workers=max_workers, **kwargs)
|
25
75
|
self._statistic = ProcessPoolStatistic()
|
26
76
|
self._statistic.processes = max_workers
|
@@ -31,6 +81,9 @@ class ProcessPoolExecutor(ProcessPoolExecutorBase, EventLoopMixin):
|
|
31
81
|
start_time: float,
|
32
82
|
loop: asyncio.AbstractEventLoop,
|
33
83
|
) -> None:
|
84
|
+
"""
|
85
|
+
Callback for statistic
|
86
|
+
"""
|
34
87
|
if future.exception():
|
35
88
|
self._statistic.error += 1
|
36
89
|
else:
|
@@ -52,4 +105,7 @@ class ProcessPoolExecutor(ProcessPoolExecutorBase, EventLoopMixin):
|
|
52
105
|
return future
|
53
106
|
|
54
107
|
def __del__(self) -> None:
|
108
|
+
"""
|
109
|
+
Cleanup resources
|
110
|
+
"""
|
55
111
|
self.shutdown()
|
aiomisc/version.py
CHANGED
@@ -15,7 +15,7 @@ aiomisc/periodic.py,sha256=OFYZbPkcGgeMjBk8zwsLr2TqPRTS6MNewaL3q9qK5js,2252
|
|
15
15
|
aiomisc/plugins/__init__.py,sha256=eHKGec_217rBjXGf8u-Joyf7dzpO1O0QAuFan1IEyYE,1057
|
16
16
|
aiomisc/plugins/__main__.py,sha256=y3mykRQmimDRHb_PvY4n08vegjWTjd9CONFbCecAxxw,1365
|
17
17
|
aiomisc/pool.py,sha256=kmTEziX7U1kXxmNsTEain9Jkzn8ZbFubuCYWaozZoRk,5764
|
18
|
-
aiomisc/process_pool.py,sha256=
|
18
|
+
aiomisc/process_pool.py,sha256=3O5FSIVQ6r-jf07Oyjs8Zt0wTL6cNZpV-tENwuQB63Y,3468
|
19
19
|
aiomisc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
20
|
aiomisc/recurring.py,sha256=LJ13P_OhZM6mVOed8iUrS-M9PXY12516XBZcFtO7XtI,4923
|
21
21
|
aiomisc/service/__init__.py,sha256=_JSkI4Q78UljG4CvhK6He2UGLxJaQS6cVwZ9QT0cSWo,607
|
@@ -45,7 +45,7 @@ aiomisc/signal.py,sha256=_iiC2jukXg7-LLirIl1YATlKIIsKLbmTNFr1Ezheu7g,1728
|
|
45
45
|
aiomisc/thread_pool.py,sha256=591u5HV1aBmBRcaVm4kAtMLPZOb6veqhT9wkts_knqE,14017
|
46
46
|
aiomisc/timeout.py,sha256=5jNDooLW4MAe6ZUIKhkiX29CoyI0zlXd-dZoZwQPxak,920
|
47
47
|
aiomisc/utils.py,sha256=6yTfTpeRCVzfZp-MJCmB1oayOHUBVwQwzC3U5PBAjn8,11919
|
48
|
-
aiomisc/version.py,sha256=
|
48
|
+
aiomisc/version.py,sha256=Y_Hh7bO575bzAAjob0MVcTO2snhkxY071G3VN3jeJlY,154
|
49
49
|
aiomisc/worker_pool.py,sha256=GA91KdOrBlqHthbVSTxu_d6BsBIbl-uKqW2NxqSafG0,11107
|
50
50
|
aiomisc_log/__init__.py,sha256=N3g8Ea1YE2dWPDd-MwohuAn3Y0pBxSyL4l4Jsxqkv0Q,4854
|
51
51
|
aiomisc_log/enum.py,sha256=_zfCZPYCGyI9KL6TqHiYVlOfA5U5MCbsuCuDKxDHdxg,1549
|
@@ -63,8 +63,8 @@ aiomisc_worker/process_inner.py,sha256=8ZtjCSLrgySW57OIbuGrpEWxfysRLYKx1or1YaAqx
|
|
63
63
|
aiomisc_worker/protocol.py,sha256=1smmlBbdreSmnrxuhHaUMUC10FO9xMIEcedhweQJX_A,2705
|
64
64
|
aiomisc_worker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
65
65
|
aiomisc_worker/worker.py,sha256=f8nCFhlKh84UUBUaEgCllwMRvVZiD8_UUXaeit6g3T8,3236
|
66
|
-
aiomisc-17.7.
|
67
|
-
aiomisc-17.7.
|
68
|
-
aiomisc-17.7.
|
69
|
-
aiomisc-17.7.
|
70
|
-
aiomisc-17.7.
|
66
|
+
aiomisc-17.7.3.dist-info/COPYING,sha256=Ky_8CQMaIixfyOreUBsl0hKN6A5fLnPF8KPQ9molMYA,1125
|
67
|
+
aiomisc-17.7.3.dist-info/METADATA,sha256=NphOM-GzSvENM9m8BK0lptTofiQqACJiag1UC9atxyE,15685
|
68
|
+
aiomisc-17.7.3.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
69
|
+
aiomisc-17.7.3.dist-info/entry_points.txt,sha256=KRsSPCwKJyGTWrvzpwbS0yIDwzsgDA2X6f0CBWYmNao,55
|
70
|
+
aiomisc-17.7.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|