aiomisc 17.7.1__tar.gz → 17.7.5__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.
Files changed (70) hide show
  1. {aiomisc-17.7.1 → aiomisc-17.7.5}/PKG-INFO +1 -1
  2. aiomisc-17.7.5/aiomisc/process_pool.py +111 -0
  3. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/recurring.py +2 -2
  4. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/periodic.py +2 -2
  5. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/version.py +2 -2
  6. {aiomisc-17.7.1 → aiomisc-17.7.5}/pyproject.toml +1 -1
  7. aiomisc-17.7.1/aiomisc/process_pool.py +0 -55
  8. {aiomisc-17.7.1 → aiomisc-17.7.5}/COPYING +0 -0
  9. {aiomisc-17.7.1 → aiomisc-17.7.5}/README.rst +0 -0
  10. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/__init__.py +0 -0
  11. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/_context_vars.py +0 -0
  12. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/aggregate.py +0 -0
  13. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/backoff.py +0 -0
  14. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/circuit_breaker.py +0 -0
  15. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/compat.py +0 -0
  16. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/context.py +0 -0
  17. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/counters.py +0 -0
  18. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/cron.py +0 -0
  19. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/entrypoint.py +0 -0
  20. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/io.py +0 -0
  21. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/iterator_wrapper.py +0 -0
  22. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/log.py +0 -0
  23. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/periodic.py +0 -0
  24. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/plugins/__init__.py +0 -0
  25. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/plugins/__main__.py +0 -0
  26. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/pool.py +0 -0
  27. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/py.typed +0 -0
  28. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/__init__.py +0 -0
  29. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/aiohttp.py +0 -0
  30. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/asgi.py +0 -0
  31. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/base.py +0 -0
  32. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/carbon.py +0 -0
  33. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/cron.py +0 -0
  34. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/__init__.py +0 -0
  35. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/records.py +0 -0
  36. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/service.py +0 -0
  37. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/store.py +0 -0
  38. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/tree.py +0 -0
  39. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/dns/zone.py +0 -0
  40. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/grpc_server.py +0 -0
  41. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/process.py +0 -0
  42. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/profiler.py +0 -0
  43. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/raven.py +0 -0
  44. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/sdwatchdog.py +0 -0
  45. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/tcp.py +0 -0
  46. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/tls.py +0 -0
  47. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/tracer.py +0 -0
  48. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/udp.py +0 -0
  49. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/service/uvicorn.py +0 -0
  50. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/signal.py +0 -0
  51. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/thread_pool.py +0 -0
  52. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/timeout.py +0 -0
  53. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/utils.py +0 -0
  54. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc/worker_pool.py +0 -0
  55. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/__init__.py +0 -0
  56. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/enum.py +0 -0
  57. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/formatter/__init__.py +0 -0
  58. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/formatter/color.py +0 -0
  59. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/formatter/journald.py +0 -0
  60. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/formatter/json.py +0 -0
  61. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/formatter/rich.py +0 -0
  62. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_log/py.typed +0 -0
  63. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/__init__.py +0 -0
  64. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/__main__.py +0 -0
  65. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/forking.py +0 -0
  66. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/process.py +0 -0
  67. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/process_inner.py +0 -0
  68. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/protocol.py +0 -0
  69. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/py.typed +0 -0
  70. {aiomisc-17.7.1 → aiomisc-17.7.5}/aiomisc_worker/worker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aiomisc
3
- Version: 17.7.1
3
+ Version: 17.7.5
4
4
  Summary: aiomisc - miscellaneous utils for asyncio
5
5
  License: MIT
6
6
  Author: Dmitry Orlov
@@ -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()
@@ -48,14 +48,14 @@ class RecurringCallback:
48
48
 
49
49
  def __init__(
50
50
  self, coroutine_func: CallbackType,
51
- *args: Any, **kwargs: Any,
51
+ *args: Any, name: Optional[str] = None, **kwargs: Any,
52
52
  ):
53
53
  self.func: Callable[..., Awaitable[Any]]
54
54
  self.args: Tuple[Any, ...]
55
55
  self.kwargs: Mapping[str, Any]
56
56
  self._statistic: RecurringCallbackStatistic
57
57
 
58
- self.name: str = repr(coroutine_func)
58
+ self.name: str = name or repr(coroutine_func)
59
59
  self._statistic = RecurringCallbackStatistic(name=self.name)
60
60
  self.func = utils.awaitable(coroutine_func)
61
61
  self.args = args
@@ -15,9 +15,9 @@ class PeriodicService(Service):
15
15
  interval: Union[int, float]
16
16
  delay: Union[int, float] = 0
17
17
 
18
- def __init__(self, **kwargs: Any):
18
+ def __init__(self, *, name: Optional[str] = None, **kwargs: Any):
19
19
  super().__init__(**kwargs)
20
- self.periodic = PeriodicCallback(self.callback)
20
+ self.periodic = PeriodicCallback(self.callback, name=name)
21
21
 
22
22
  async def start(self) -> None:
23
23
  assert self.interval, f"Interval illegal interval {self.interval!r}"
@@ -2,5 +2,5 @@
2
2
  # BY: poem-plugins "git" plugin
3
3
  # NEVER EDIT THIS FILE MANUALLY
4
4
 
5
- version_info = (17, 7, 1)
6
- __version__ = "17.7.1"
5
+ version_info = (17, 7, 5)
6
+ __version__ = "17.7.5"
@@ -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.7.1"
4
+ version = "17.7.5"
5
5
  description = "aiomisc - miscellaneous utils for asyncio"
6
6
  authors = ["Dmitry Orlov <me@mosquito.su>"]
7
7
  readme = "README.rst"
@@ -1,55 +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
- """
43
- Submit blocking function to the pool
44
- """
45
- loop = asyncio.get_running_loop()
46
- start_time = loop.time()
47
- future = super().submit(*args, **kwargs)
48
- self._statistic.submitted += 1
49
- future.add_done_callback(
50
- lambda f: self._statistic_callback(f, start_time, loop),
51
- )
52
- return future
53
-
54
- def __del__(self) -> None:
55
- 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