aiomisc 17.6.3__tar.gz → 17.7.3__tar.gz
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-17.6.3 → aiomisc-17.7.3}/PKG-INFO +3 -4
- aiomisc-17.7.3/aiomisc/process_pool.py +111 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/tls.py +57 -8
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/version.py +2 -2
- {aiomisc-17.6.3 → aiomisc-17.7.3}/pyproject.toml +6 -6
- aiomisc-17.6.3/aiomisc/process_pool.py +0 -53
- {aiomisc-17.6.3 → aiomisc-17.7.3}/COPYING +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/README.rst +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/_context_vars.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/aggregate.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/backoff.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/circuit_breaker.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/compat.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/context.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/counters.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/cron.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/entrypoint.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/io.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/iterator_wrapper.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/log.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/periodic.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/plugins/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/plugins/__main__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/pool.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/py.typed +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/recurring.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/aiohttp.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/asgi.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/base.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/carbon.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/cron.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/records.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/service.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/store.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/tree.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/dns/zone.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/grpc_server.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/periodic.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/process.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/profiler.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/raven.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/sdwatchdog.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/tcp.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/tracer.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/udp.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/service/uvicorn.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/signal.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/thread_pool.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/timeout.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/utils.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc/worker_pool.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/enum.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/formatter/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/formatter/color.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/formatter/journald.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/formatter/json.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/formatter/rich.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_log/py.typed +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/__init__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/__main__.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/forking.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/process.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/process_inner.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/protocol.py +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/py.typed +0 -0
- {aiomisc-17.6.3 → aiomisc-17.7.3}/aiomisc_worker/worker.py +0 -0
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: aiomisc
|
3
|
-
Version: 17.
|
3
|
+
Version: 17.7.3
|
4
4
|
Summary: aiomisc - miscellaneous utils for asyncio
|
5
5
|
License: MIT
|
6
6
|
Author: Dmitry Orlov
|
7
7
|
Author-email: me@mosquito.su
|
8
|
-
Requires-Python: >=3.
|
8
|
+
Requires-Python: >=3.9,<4.0
|
9
9
|
Classifier: Development Status :: 5 - Production/Stable
|
10
10
|
Classifier: Framework :: AsyncIO
|
11
11
|
Classifier: Framework :: Pytest
|
@@ -23,7 +23,6 @@ Classifier: Operating System :: POSIX
|
|
23
23
|
Classifier: Operating System :: POSIX :: Linux
|
24
24
|
Classifier: Programming Language :: Python
|
25
25
|
Classifier: Programming Language :: Python :: 3
|
26
|
-
Classifier: Programming Language :: Python :: 3.8
|
27
26
|
Classifier: Programming Language :: Python :: 3.9
|
28
27
|
Classifier: Programming Language :: Python :: 3.10
|
29
28
|
Classifier: Programming Language :: Python :: 3.11
|
@@ -66,7 +65,7 @@ Requires-Dist: rich ; extra == "rich"
|
|
66
65
|
Requires-Dist: setuptools ; python_version < "3.8"
|
67
66
|
Requires-Dist: typing_extensions ; python_version < "3.10"
|
68
67
|
Requires-Dist: uvicorn (>=0.27,<0.28) ; extra == "uvicorn"
|
69
|
-
Requires-Dist: uvloop (>=0.
|
68
|
+
Requires-Dist: uvloop (>=0.21,<1) ; extra == "uvloop"
|
70
69
|
Project-URL: Changelog, https://github.com/aiokitchen/aiomisc/blob/master/CHANGELOG.md
|
71
70
|
Project-URL: Documentation, https://docs.aiomisc.com/
|
72
71
|
Project-URL: Homepage, https://github.com/aiokitchen/aiomisc
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import asyncio
|
2
|
+
from concurrent.futures import Future
|
3
|
+
from concurrent.futures import ProcessPoolExecutor as ProcessPoolExecutorBase
|
4
|
+
from multiprocessing import cpu_count
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
from .compat import EventLoopMixin
|
8
|
+
from .counters import Statistic
|
9
|
+
|
10
|
+
|
11
|
+
class ProcessPoolStatistic(Statistic):
|
12
|
+
processes: int
|
13
|
+
done: int
|
14
|
+
error: int
|
15
|
+
success: int
|
16
|
+
submitted: int
|
17
|
+
sum_time: float
|
18
|
+
|
19
|
+
|
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
|
+
|
46
|
+
DEFAULT_MAX_WORKERS = max((cpu_count(), 4))
|
47
|
+
|
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
|
+
"""
|
74
|
+
super().__init__(max_workers=max_workers, **kwargs)
|
75
|
+
self._statistic = ProcessPoolStatistic()
|
76
|
+
self._statistic.processes = max_workers
|
77
|
+
|
78
|
+
def _statistic_callback(
|
79
|
+
self,
|
80
|
+
future: Future,
|
81
|
+
start_time: float,
|
82
|
+
loop: asyncio.AbstractEventLoop,
|
83
|
+
) -> None:
|
84
|
+
"""
|
85
|
+
Callback for statistic
|
86
|
+
"""
|
87
|
+
if future.exception():
|
88
|
+
self._statistic.error += 1
|
89
|
+
else:
|
90
|
+
self._statistic.success += 1
|
91
|
+
self._statistic.done += 1
|
92
|
+
self._statistic.sum_time += loop.time() - start_time
|
93
|
+
|
94
|
+
def submit(self, *args: Any, **kwargs: Any) -> Future:
|
95
|
+
"""
|
96
|
+
Submit blocking function to the pool
|
97
|
+
"""
|
98
|
+
loop = asyncio.get_running_loop()
|
99
|
+
start_time = loop.time()
|
100
|
+
future = super().submit(*args, **kwargs)
|
101
|
+
self._statistic.submitted += 1
|
102
|
+
future.add_done_callback(
|
103
|
+
lambda f: self._statistic_callback(f, start_time, loop),
|
104
|
+
)
|
105
|
+
return future
|
106
|
+
|
107
|
+
def __del__(self) -> None:
|
108
|
+
"""
|
109
|
+
Cleanup resources
|
110
|
+
"""
|
111
|
+
self.shutdown()
|
@@ -17,6 +17,19 @@ PathOrStr = Union[Path, str]
|
|
17
17
|
log = logging.getLogger(__name__)
|
18
18
|
|
19
19
|
|
20
|
+
DEFAULT_SSL_CIPHERS = (
|
21
|
+
"ECDHE-RSA-AES256-GCM-SHA384",
|
22
|
+
"ECDHE-ECDSA-AES256-GCM-SHA384",
|
23
|
+
"ECDHE-RSA-CHACHA20-POLY1305",
|
24
|
+
"ECDHE-ECDSA-CHACHA20-POLY1305",
|
25
|
+
"ECDHE-RSA-AES128-GCM-SHA256",
|
26
|
+
"ECDHE-ECDSA-AES128-GCM-SHA256",
|
27
|
+
)
|
28
|
+
|
29
|
+
DEFAULT_SSL_MIN_VERSION = ssl.TLSVersion.TLSv1_3
|
30
|
+
DEFAULT_SSL_MAX_VERSION = ssl.TLSVersion.TLSv1_3
|
31
|
+
|
32
|
+
|
20
33
|
@dataclass(frozen=True)
|
21
34
|
class SSLOptionsBase:
|
22
35
|
cert: Optional[Path]
|
@@ -25,6 +38,9 @@ class SSLOptionsBase:
|
|
25
38
|
verify: bool
|
26
39
|
require_client_cert: bool
|
27
40
|
purpose: ssl.Purpose
|
41
|
+
minimum_version: ssl.TLSVersion = DEFAULT_SSL_MIN_VERSION
|
42
|
+
maximum_version: ssl.TLSVersion = DEFAULT_SSL_MAX_VERSION
|
43
|
+
ciphers: Tuple[str, ...] = DEFAULT_SSL_CIPHERS
|
28
44
|
|
29
45
|
|
30
46
|
class SSLOptions(SSLOptionsBase):
|
@@ -32,6 +48,9 @@ class SSLOptions(SSLOptionsBase):
|
|
32
48
|
self, cert: Optional[PathOrStr], key: Optional[PathOrStr],
|
33
49
|
ca: Optional[PathOrStr], verify: bool, require_client_cert: bool,
|
34
50
|
purpose: ssl.Purpose,
|
51
|
+
minimum_version: ssl.TLSVersion = DEFAULT_SSL_MIN_VERSION,
|
52
|
+
maximum_version: ssl.TLSVersion = DEFAULT_SSL_MAX_VERSION,
|
53
|
+
ciphers: Tuple[str, ...] = DEFAULT_SSL_CIPHERS,
|
35
54
|
) -> None:
|
36
55
|
super().__init__(
|
37
56
|
cert=Path(cert) if cert else None,
|
@@ -40,25 +59,48 @@ class SSLOptions(SSLOptionsBase):
|
|
40
59
|
verify=verify,
|
41
60
|
require_client_cert=require_client_cert,
|
42
61
|
purpose=purpose,
|
62
|
+
minimum_version=minimum_version,
|
63
|
+
maximum_version=maximum_version,
|
64
|
+
ciphers=ciphers,
|
43
65
|
)
|
44
66
|
|
45
67
|
def create_context(self) -> ssl.SSLContext:
|
46
68
|
context = ssl.create_default_context(
|
47
|
-
purpose=self.purpose,
|
69
|
+
purpose=self.purpose,
|
48
70
|
)
|
49
71
|
|
50
|
-
|
51
|
-
|
72
|
+
# Disable compression to prevent CRIME attacks
|
73
|
+
context.options |= ssl.OP_NO_COMPRESSION
|
74
|
+
|
75
|
+
context.maximum_version = self.maximum_version
|
76
|
+
context.minimum_version = self.minimum_version
|
77
|
+
context.set_ciphers(":".join(self.ciphers))
|
78
|
+
|
79
|
+
if not self.verify:
|
80
|
+
context.check_hostname = False
|
81
|
+
|
82
|
+
if self.ca:
|
83
|
+
log.debug("Loading CA from %s", self.ca)
|
84
|
+
if not self.ca.exists():
|
85
|
+
raise FileNotFoundError(
|
86
|
+
"CA file doesn't exists", str(self.ca.resolve()),
|
87
|
+
)
|
88
|
+
context.load_verify_locations(cafile=str(self.ca))
|
52
89
|
|
53
90
|
if self.require_client_cert:
|
91
|
+
log.debug("Set server-side cert verification")
|
54
92
|
context.verify_mode = ssl.VerifyMode.CERT_REQUIRED
|
93
|
+
# Post-handshake authentication is required
|
94
|
+
context.post_handshake_auth = True
|
95
|
+
else:
|
96
|
+
# Disable server-side cert verification
|
97
|
+
context.check_hostname = False
|
98
|
+
context.verify_mode = ssl.VerifyMode.CERT_NONE
|
55
99
|
|
100
|
+
# Load server-side cert and key
|
56
101
|
if self.key and self.cert:
|
57
102
|
context.load_cert_chain(self.cert, self.key)
|
58
103
|
|
59
|
-
if not self.verify:
|
60
|
-
context.check_hostname = False
|
61
|
-
|
62
104
|
return context
|
63
105
|
|
64
106
|
|
@@ -69,13 +111,20 @@ class TLSServer(SimpleServer):
|
|
69
111
|
self, *, address: Optional[str] = None, port: Optional[int] = None,
|
70
112
|
cert: PathOrStr, key: PathOrStr, ca: Optional[PathOrStr] = None,
|
71
113
|
require_client_cert: bool = False, verify: bool = True,
|
114
|
+
minimum_version: ssl.TLSVersion = DEFAULT_SSL_MIN_VERSION,
|
115
|
+
maximum_version: ssl.TLSVersion = DEFAULT_SSL_MAX_VERSION,
|
116
|
+
ciphers: Tuple[str, ...] = DEFAULT_SSL_CIPHERS,
|
72
117
|
options: OptionsType = (), sock: Optional[socket.socket] = None,
|
73
118
|
**kwargs: Any,
|
74
119
|
):
|
75
120
|
|
76
121
|
self.__ssl_options = SSLOptions(
|
77
|
-
cert, key, ca, verify,
|
78
|
-
|
122
|
+
cert=cert, key=key, ca=ca, verify=verify,
|
123
|
+
require_client_cert=require_client_cert,
|
124
|
+
purpose=ssl.Purpose.CLIENT_AUTH,
|
125
|
+
minimum_version=minimum_version,
|
126
|
+
maximum_version=maximum_version,
|
127
|
+
ciphers=ciphers,
|
79
128
|
)
|
80
129
|
|
81
130
|
if not sock:
|
@@ -1,7 +1,7 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "aiomisc"
|
3
3
|
# This is a dummy version which will be rewritten with poem-plugins
|
4
|
-
version = "17.
|
4
|
+
version = "17.7.3"
|
5
5
|
description = "aiomisc - miscellaneous utils for asyncio"
|
6
6
|
authors = ["Dmitry Orlov <me@mosquito.su>"]
|
7
7
|
readme = "README.rst"
|
@@ -24,11 +24,11 @@ classifiers = [
|
|
24
24
|
"Operating System :: POSIX :: Linux",
|
25
25
|
"Operating System :: POSIX",
|
26
26
|
"Programming Language :: Python :: 3",
|
27
|
-
"Programming Language :: Python :: 3.8",
|
28
27
|
"Programming Language :: Python :: 3.9",
|
29
28
|
"Programming Language :: Python :: 3.10",
|
30
29
|
"Programming Language :: Python :: 3.11",
|
31
30
|
"Programming Language :: Python :: 3.12",
|
31
|
+
"Programming Language :: Python :: 3.13",
|
32
32
|
"Programming Language :: Python :: Implementation :: CPython",
|
33
33
|
"Programming Language :: Python",
|
34
34
|
"Topic :: Internet :: WWW/HTTP",
|
@@ -55,7 +55,7 @@ packages = [
|
|
55
55
|
"Documentation" = "https://docs.aiomisc.com/"
|
56
56
|
|
57
57
|
[tool.poetry.dependencies]
|
58
|
-
python = "^3.
|
58
|
+
python = "^3.9"
|
59
59
|
aiocarbon = { version = "^0.15", optional = true }
|
60
60
|
aiohttp = { version = ">3", optional = true }
|
61
61
|
aiohttp-asgi = { version = "^0.5.2", optional = true }
|
@@ -69,14 +69,14 @@ raven = { version = "*", optional = true }
|
|
69
69
|
rich = { version = "*", optional = true }
|
70
70
|
setuptools = [{ version = '*', python = "< 3.8" }]
|
71
71
|
typing_extensions = [{ version = '*', python = "< 3.10" }]
|
72
|
-
uvloop = { version = ">=0.
|
72
|
+
uvloop = { version = ">=0.21, <1", optional = true }
|
73
73
|
uvicorn = { version = "^0.27", optional = true }
|
74
74
|
asgiref = { version = "^3.7", optional = true }
|
75
75
|
dnslib = { version = "^0.9", optional = true }
|
76
76
|
|
77
77
|
[tool.poetry.group.dev.dependencies]
|
78
78
|
aiocarbon = "^0.15.3"
|
79
|
-
aiohttp = "^3.
|
79
|
+
aiohttp = "^3.11"
|
80
80
|
aiohttp-asgi = "~0.5.2"
|
81
81
|
aiomisc-pytest = "^1.0.8"
|
82
82
|
asgiref = "^3.7"
|
@@ -116,7 +116,7 @@ pytest-rerunfailures = "^14.0"
|
|
116
116
|
sphinxcontrib-googleanalytics = "^0.4"
|
117
117
|
|
118
118
|
[tool.poetry.group.uvloop.dependencies]
|
119
|
-
uvloop = "^0.
|
119
|
+
uvloop = "^0.21"
|
120
120
|
|
121
121
|
[tool.poetry.extras]
|
122
122
|
aiohttp = ["aiohttp"]
|
@@ -1,53 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
from concurrent.futures import Future
|
3
|
-
from concurrent.futures import ProcessPoolExecutor as ProcessPoolExecutorBase
|
4
|
-
from multiprocessing import cpu_count
|
5
|
-
from typing import Any
|
6
|
-
|
7
|
-
from .compat import EventLoopMixin
|
8
|
-
from .counters import Statistic
|
9
|
-
|
10
|
-
|
11
|
-
class ProcessPoolStatistic(Statistic):
|
12
|
-
processes: int
|
13
|
-
done: int
|
14
|
-
error: int
|
15
|
-
success: int
|
16
|
-
submitted: int
|
17
|
-
sum_time: float
|
18
|
-
|
19
|
-
|
20
|
-
class ProcessPoolExecutor(ProcessPoolExecutorBase, EventLoopMixin):
|
21
|
-
DEFAULT_MAX_WORKERS = max((cpu_count(), 4))
|
22
|
-
|
23
|
-
def __init__(self, max_workers: int = DEFAULT_MAX_WORKERS, **kwargs: Any):
|
24
|
-
super().__init__(max_workers=max_workers, **kwargs)
|
25
|
-
self._statistic = ProcessPoolStatistic()
|
26
|
-
self._statistic.processes = max_workers
|
27
|
-
|
28
|
-
def _statistic_callback(
|
29
|
-
self,
|
30
|
-
future: Future,
|
31
|
-
start_time: float,
|
32
|
-
loop: asyncio.AbstractEventLoop,
|
33
|
-
) -> None:
|
34
|
-
if future.exception():
|
35
|
-
self._statistic.error += 1
|
36
|
-
else:
|
37
|
-
self._statistic.success += 1
|
38
|
-
self._statistic.done += 1
|
39
|
-
self._statistic.sum_time += loop.time() - start_time
|
40
|
-
|
41
|
-
def submit(self, *args: Any, **kwargs: Any) -> Future:
|
42
|
-
"""Submit blocking function to the pool"""
|
43
|
-
loop = asyncio.get_running_loop()
|
44
|
-
start_time = loop.time()
|
45
|
-
future = super().submit(*args, **kwargs)
|
46
|
-
self._statistic.submitted += 1
|
47
|
-
future.add_done_callback(
|
48
|
-
lambda f: self._statistic_callback(f, start_time, loop),
|
49
|
-
)
|
50
|
-
return future
|
51
|
-
|
52
|
-
def __del__(self) -> None:
|
53
|
-
self.shutdown()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|