mm-std 0.3.18__py3-none-any.whl → 0.3.20__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.
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import asyncio
4
4
  from collections.abc import Awaitable
5
5
  from dataclasses import dataclass
6
+ from logging import Logger
6
7
  from typing import Any
7
8
 
8
9
 
@@ -26,17 +27,21 @@ class AsyncTaskRunner:
26
27
  task_id: str
27
28
  awaitable: Awaitable[Any]
28
29
 
29
- def __init__(self, max_concurrent_tasks: int, timeout: float | None = None, name: str | None = None) -> None:
30
+ def __init__(
31
+ self, max_concurrent_tasks: int, timeout: float | None = None, name: str | None = None, logger: Logger | None = None
32
+ ) -> None:
30
33
  """
31
34
  :param max_concurrent_tasks: Maximum number of tasks that can run concurrently.
32
35
  :param timeout: Optional overall timeout in seconds for running all tasks.
33
36
  :param name: Optional name for the runner.
37
+ :param logger: Optional logger for task exceptions.
34
38
  """
35
39
  if timeout is not None and timeout <= 0:
36
40
  raise ValueError("Timeout must be positive if specified.")
37
41
  self.max_concurrent_tasks: int = max_concurrent_tasks
38
42
  self.timeout: float | None = timeout
39
43
  self.name = name
44
+ self.logger = logger
40
45
  self.semaphore: asyncio.Semaphore = asyncio.Semaphore(max_concurrent_tasks)
41
46
  self._tasks: list[AsyncTaskRunner.Task] = []
42
47
  self._was_run: bool = False
@@ -67,6 +72,9 @@ class AsyncTaskRunner:
67
72
  self._task_ids.add(task_id)
68
73
  self._tasks.append(AsyncTaskRunner.Task(task_id, awaitable))
69
74
 
75
+ def _task_name(self, task_id: str) -> str:
76
+ return f"{self.name}-{task_id}" if self.name else task_id
77
+
70
78
  async def run(self) -> AsyncTaskRunner.Result:
71
79
  """
72
80
  Executes all added tasks with concurrency limited by the semaphore.
@@ -89,10 +97,12 @@ class AsyncTaskRunner:
89
97
  res: Any = await task.awaitable
90
98
  results[task.task_id] = res
91
99
  except Exception as e:
100
+ if self.logger:
101
+ self.logger.exception(f"Task '{self._task_name(task.task_id)}' raised an exception")
92
102
  exceptions[task.task_id] = e
93
103
 
94
104
  # Create asyncio tasks for all runner tasks
95
- tasks = [asyncio.create_task(run_task(task)) for task in self._tasks]
105
+ tasks = [asyncio.create_task(run_task(task), name=self._task_name(task.task_id)) for task in self._tasks]
96
106
 
97
107
  try:
98
108
  if self.timeout is not None:
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-std
3
- Version: 0.3.18
3
+ Version: 0.3.20
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: aiohttp-socks~=0.10.1
6
6
  Requires-Dist: aiohttp~=3.11.14
7
7
  Requires-Dist: cryptography~=44.0.2
8
8
  Requires-Dist: pydantic-settings>=2.8.1
9
- Requires-Dist: pydantic~=2.10.6
9
+ Requires-Dist: pydantic~=2.11.0
10
10
  Requires-Dist: pydash~=8.0.5
11
11
  Requires-Dist: python-dotenv~=1.1.0
12
12
  Requires-Dist: requests[socks]~=2.32.3
@@ -21,10 +21,10 @@ mm_std/zip.py,sha256=axzF1BwcIygtfNNTefZH7hXKaQqwe-ZH3ChuRWr9dnk,396
21
21
  mm_std/concurrency/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  mm_std/concurrency/async_decorators.py,sha256=xEpyipzp3ZhaPHtdeTE-Ikrt67SUTFKBE6LQPeoeh6Q,1735
23
23
  mm_std/concurrency/async_scheduler.py,sha256=qS3QKMA0xpoxCZWjDW1ItAwKMTQ5h8esXMMRA0eXtxE,5644
24
- mm_std/concurrency/async_task_runner.py,sha256=zYC2Jv5taUh8dnyDfWwh394SkzTXtdE9hOhvjV2FWKc,4493
24
+ mm_std/concurrency/async_task_runner.py,sha256=KyTp4aHt-qBc-qJpXIutFaTP9ykupG7uKafghAwbBvg,4948
25
25
  mm_std/concurrency/sync_decorators.py,sha256=syCQBOmN7qPO55yzgJB2rbkh10CVww376hmyvs6e5tA,1080
26
26
  mm_std/concurrency/sync_scheduler.py,sha256=j4tBL_cBI1spr0cZplTA7N2CoYsznuORMeRN8rpR6gY,2407
27
27
  mm_std/concurrency/sync_task_runner.py,sha256=s5JPlLYLGQGHIxy4oDS-PN7O9gcy-yPZFoNm8RQwzcw,1780
28
- mm_std-0.3.18.dist-info/METADATA,sha256=AUl95Lq0McMhB-E8PsxqPEbYsxuiQI0cA1t5AX208qg,415
29
- mm_std-0.3.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
- mm_std-0.3.18.dist-info/RECORD,,
28
+ mm_std-0.3.20.dist-info/METADATA,sha256=bcvPFhVCzwNBhB8qz0DW1AZY_jeKqdFIuMiOHHz-22I,415
29
+ mm_std-0.3.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ mm_std-0.3.20.dist-info/RECORD,,