mm-std 0.3.14__py3-none-any.whl → 0.3.16__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.
@@ -1,7 +1,9 @@
1
+ import asyncio
1
2
  import threading
2
3
  from dataclasses import dataclass, field
3
4
  from datetime import datetime
4
5
  from logging import Logger
6
+ from typing import Any
5
7
 
6
8
  import anyio
7
9
 
@@ -26,6 +28,7 @@ class AsyncScheduler:
26
28
  self.tasks: dict[str, AsyncScheduler.TaskInfo] = {}
27
29
  self._running: bool = False
28
30
  self._cancel_scope: anyio.CancelScope | None = None
31
+ self._main_task: asyncio.Task[Any] | None = None
29
32
  self._thread: threading.Thread | None = None
30
33
  self._logger = logger
31
34
 
@@ -82,8 +85,9 @@ class AsyncScheduler:
82
85
  return
83
86
  self._running = True
84
87
  self._logger.debug("Starting AsyncScheduler")
85
- self._thread = threading.Thread(target=lambda: anyio.run(self._start_all_tasks), daemon=True, name="AsyncScheduler")
86
- self._thread.start()
88
+
89
+ # Create a task in the current event loop
90
+ self._main_task = asyncio.create_task(self._start_all_tasks())
87
91
 
88
92
  def stop(self) -> None:
89
93
  """
mm_std/http_.py CHANGED
@@ -3,6 +3,7 @@ from dataclasses import asdict, dataclass, field
3
3
  from typing import Any
4
4
  from urllib.parse import urlencode
5
5
 
6
+ import anyio
6
7
  import httpx
7
8
  import pydash
8
9
  import requests
@@ -170,31 +171,33 @@ async def async_hrequest(
170
171
  else:
171
172
  data = params
172
173
 
173
- try:
174
- async with httpx.AsyncClient(
175
- proxy=proxy,
176
- timeout=timeout,
177
- cookies=cookies,
178
- auth=auth,
179
- verify=verify,
180
- ) as client:
181
- r = await client.request(
182
- method,
183
- url,
184
- headers=headers,
185
- params=query_params,
186
- json=json_,
187
- data=data,
188
- )
189
- return HResponse(code=r.status_code, body=r.text, headers=dict(r.headers))
190
- except httpx.TimeoutException:
191
- return HResponse(error="timeout")
192
- except httpx.ProxyError:
193
- return HResponse(error="proxy_error")
194
- except httpx.RequestError as err:
195
- return HResponse(error=f"connection_error: {err}")
196
- except Exception as err:
197
- return HResponse(error=f"exception: {err}")
174
+ with anyio.move_on_after(timeout):
175
+ try:
176
+ async with httpx.AsyncClient(
177
+ proxy=proxy,
178
+ timeout=timeout,
179
+ cookies=cookies,
180
+ auth=auth,
181
+ verify=verify,
182
+ ) as client:
183
+ r = await client.request(
184
+ method,
185
+ url,
186
+ headers=headers,
187
+ params=query_params,
188
+ json=json_,
189
+ data=data,
190
+ )
191
+ return HResponse(code=r.status_code, body=r.text, headers=dict(r.headers))
192
+ except httpx.TimeoutException:
193
+ return HResponse(error="timeout")
194
+ except httpx.ProxyError:
195
+ return HResponse(error="proxy_error")
196
+ except httpx.RequestError as err:
197
+ return HResponse(error=f"connection_error: {err}")
198
+ except Exception as err:
199
+ return HResponse(error=f"exception: {err}")
200
+ return HResponse(error="timeout")
198
201
 
199
202
 
200
203
  def add_query_params_to_url(url: str, params: dict[str, object]) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-std
3
- Version: 0.3.14
3
+ Version: 0.3.16
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: anyio>=4.9.0
6
6
  Requires-Dist: cryptography~=44.0.2
@@ -8,7 +8,7 @@ Requires-Dist: httpx[socks]>=0.28.1
8
8
  Requires-Dist: pydantic-settings>=2.8.1
9
9
  Requires-Dist: pydantic~=2.10.6
10
10
  Requires-Dist: pydash~=8.0.5
11
- Requires-Dist: python-dotenv~=1.0.1
11
+ Requires-Dist: python-dotenv~=1.1.0
12
12
  Requires-Dist: requests[socks]~=2.32.3
13
13
  Requires-Dist: rich~=13.9.4
14
14
  Requires-Dist: tomlkit~=0.13.2
@@ -6,7 +6,7 @@ mm_std/date.py,sha256=976eEkSONuNqHQBgSRu8hrtH23tJqztbmHFHLdbP2TY,1879
6
6
  mm_std/dict.py,sha256=6GkhJPXD0LiJDxPcYe6jPdEDw-MN7P7mKu6U5XxwYDk,675
7
7
  mm_std/env.py,sha256=5zaR9VeIfObN-4yfgxoFeU5IM1GDeZZj9SuYf7t9sOA,125
8
8
  mm_std/fs.py,sha256=RwarNRJq3tIMG6LVX_g03hasfYpjYFh_O27oVDt5IPQ,291
9
- mm_std/http_.py,sha256=JkyHZ29EOC6Ulqw_5eBNLmeMrca6NDGueTSwpj96aKM,6003
9
+ mm_std/http_.py,sha256=x5d4wnQcPlB_IYaYNCQGz7iOTEft8cQmMggHt30o7xI,6193
10
10
  mm_std/json_.py,sha256=Naa6mBE4D0yiQGkPNRrFvndnUH3R7ovw3FeaejWV60o,1196
11
11
  mm_std/log.py,sha256=6ux6njNKc_ZCQlvWn1FZR6vcSY2Cem-mQzmNXvsg5IE,913
12
12
  mm_std/net.py,sha256=qdRCBIDneip6FaPNe5mx31UtYVmzqam_AoUF7ydEyjA,590
@@ -20,11 +20,11 @@ mm_std/types_.py,sha256=9FGd2q47a8M9QQgsWJR1Kq34jLxBAkYSoJuwih4PPqg,257
20
20
  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=tJ5u-_G9mAF3zrFr1aBUhYh03rB-K_6oiDKGdmGdlGk,449
23
- mm_std/concurrency/async_scheduler.py,sha256=NsR9nrxAEdiYjGL-lTdDlQAXJHJZBUYnm26h-0zaxCg,3932
23
+ mm_std/concurrency/async_scheduler.py,sha256=-crLjrFwRJSNGdyhU3brCvqP7EPPLwEVfZFbDCBe9Qo,3995
24
24
  mm_std/concurrency/async_task_runner.py,sha256=D4fD_hwSVy55sM_-U1_sdVYlkahnQeigXdMfbIi8Rpc,4492
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.14.dist-info/METADATA,sha256=sH9DFjRqCXpYR3okXUVWFsTNlbyEk98QxYIfYGbFiXg,410
29
- mm_std-0.3.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
- mm_std-0.3.14.dist-info/RECORD,,
28
+ mm_std-0.3.16.dist-info/METADATA,sha256=tXTemaQ7P5DOoxtamgJjtXkXVrhzvHOaaNyH4PavjYg,410
29
+ mm_std-0.3.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ mm_std-0.3.16.dist-info/RECORD,,