mm-std 0.3.10__py3-none-any.whl → 0.3.12__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.
mm_std/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from .async_concurrency import AsyncScheduler as AsyncScheduler
2
+ from .async_concurrency import async_synchronized as async_synchronized
2
3
  from .command import CommandResult as CommandResult
3
4
  from .command import run_command as run_command
4
5
  from .command import run_ssh_command as run_ssh_command
@@ -1,8 +1,10 @@
1
+ import functools
1
2
  import threading
2
3
  from collections.abc import Awaitable, Callable
3
4
  from dataclasses import dataclass, field
4
5
  from datetime import UTC, datetime
5
6
  from logging import Logger
7
+ from typing import ParamSpec, TypeVar
6
8
 
7
9
  import anyio
8
10
 
@@ -69,7 +71,7 @@ class AsyncScheduler:
69
71
  while self._running: # noqa: ASYNC110
70
72
  await anyio.sleep(0.1)
71
73
  except anyio.get_cancelled_exc_class():
72
- self._logger.info("Task group cancelled. Exiting _start_all_tasks.")
74
+ self._logger.debug("Task group cancelled. Exiting _start_all_tasks.")
73
75
 
74
76
  def start(self) -> None:
75
77
  """
@@ -79,11 +81,11 @@ class AsyncScheduler:
79
81
  which runs an AnyIO event loop.
80
82
  """
81
83
  if self._running:
82
- self._logger.warning("Scheduler already running")
84
+ self._logger.warning("AsyncScheduler already running")
83
85
  return
84
86
  self._running = True
85
- self._logger.info("Starting scheduler")
86
- self._thread = threading.Thread(target=lambda: anyio.run(self._start_all_tasks), daemon=True)
87
+ self._logger.debug("Starting AsyncScheduler")
88
+ self._thread = threading.Thread(target=lambda: anyio.run(self._start_all_tasks), daemon=True, name="AsyncScheduler")
87
89
  self._thread.start()
88
90
 
89
91
  def stop(self) -> None:
@@ -94,9 +96,9 @@ class AsyncScheduler:
94
96
  This method then waits for the background thread to finish.
95
97
  """
96
98
  if not self._running:
97
- self._logger.warning("Scheduler not running")
99
+ self._logger.warning("AsyncScheduler not running")
98
100
  return
99
- self._logger.info("Stopping scheduler")
101
+ self._logger.debug("Stopping AsyncScheduler")
100
102
  self._running = False
101
103
  if self._cancel_scope is not None:
102
104
  self._cancel_scope.cancel()
@@ -104,4 +106,19 @@ class AsyncScheduler:
104
106
  if self._thread:
105
107
  self._thread.join(timeout=5)
106
108
  self._thread = None
107
- self._logger.info("Scheduler stopped")
109
+ self._logger.debug("AsyncScheduler stopped")
110
+
111
+
112
+ P = ParamSpec("P")
113
+ R = TypeVar("R")
114
+
115
+
116
+ def async_synchronized(func: Callable[P, Awaitable[R]]) -> Callable[P, Awaitable[R]]:
117
+ lock = anyio.Lock()
118
+
119
+ @functools.wraps(func)
120
+ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
121
+ async with lock:
122
+ return await func(*args, **kwargs)
123
+
124
+ return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-std
3
- Version: 0.3.10
3
+ Version: 0.3.12
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: anyio>=4.9.0
6
6
  Requires-Dist: cryptography~=44.0.2
@@ -1,5 +1,5 @@
1
- mm_std/__init__.py,sha256=HBJRK8f5Qz3v3XtwT7r5lvaANNknAuoV1NsPuO9yQDc,2646
2
- mm_std/async_concurrency.py,sha256=Zp0_tcRhoGJPJ1iueXKTlJHv0IZDDYLgOmpHSvb1kKs,3925
1
+ mm_std/__init__.py,sha256=BJzVoqux6-YWxGMyXJS34v6CgKh3V7SrpV7eXIUVfbw,2718
2
+ mm_std/async_concurrency.py,sha256=IfnOx1Cwkc134P9F9_giNTyEYIXPj-LdzafPZAwA-5Y,4365
3
3
  mm_std/command.py,sha256=ze286wjUjg0QSTgIu-2WZks53_Vclg69UaYYgPpQvCU,1283
4
4
  mm_std/concurrency.py,sha256=4kKLhde6YQYsjJJjH6K5eMQj6FtegEz55Mo5TmhQMM0,5242
5
5
  mm_std/config.py,sha256=4ox4D2CgGR76bvZ2n2vGQOYUDagFnlKEDb87to5zpxE,1871
@@ -20,6 +20,6 @@ mm_std/str.py,sha256=BEjJ1p5O4-uSYK0h-enasSSDdwzkBbiwdQ4_dsrlEE8,3257
20
20
  mm_std/toml.py,sha256=CNznWKR0bpOxS6e3VB5LGS-Oa9lW-wterkcPUFtPcls,610
21
21
  mm_std/types_.py,sha256=hvZlnvBWyB8CL_MeEWWD0Y0nN677plibYn3yD-5g7xs,99
22
22
  mm_std/zip.py,sha256=axzF1BwcIygtfNNTefZH7hXKaQqwe-ZH3ChuRWr9dnk,396
23
- mm_std-0.3.10.dist-info/METADATA,sha256=1i_m2ldTzID9GccEEPB8ZDqs1DOlGsSdVgkoaHhNdZQ,410
24
- mm_std-0.3.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
- mm_std-0.3.10.dist-info/RECORD,,
23
+ mm_std-0.3.12.dist-info/METADATA,sha256=G3VmqlSd0N1ctXXLUyQWU8pJYHBLW98sYKoPsz97clE,410
24
+ mm_std-0.3.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ mm_std-0.3.12.dist-info/RECORD,,