mtbase 4.32.26__py3-none-any.whl → 4.32.28__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.
mt/aio/files.py CHANGED
@@ -6,6 +6,7 @@ import tempfile
6
6
  import asyncio
7
7
  import aiofiles
8
8
  import time
9
+ import psutil
9
10
 
10
11
  from mt import ctx
11
12
 
@@ -52,26 +53,22 @@ async def read_binary(filepath, size: int = None, context_vars: dict = {}) -> by
52
53
  the content read from file
53
54
  """
54
55
 
55
- if context_vars["async"]:
56
+ for i in range(3):
56
57
  try:
57
- async with aiofiles.open(filepath, mode="rb") as f:
58
- return await f.read(size)
59
- except OSError as e:
60
- if e.errno == 24: # too many open files
61
- await asyncio.sleep(1)
58
+ if context_vars["async"]:
62
59
  async with aiofiles.open(filepath, mode="rb") as f:
63
60
  return await f.read(size)
64
61
  else:
65
- raise
66
- else:
67
- try:
68
- with open(filepath, mode="rb") as f:
69
- return f.read(size)
70
- except OSError as e:
71
- if e.errno == 24: # too many open files
72
- time.sleep(1)
73
62
  with open(filepath, mode="rb") as f:
74
63
  return f.read(size)
64
+ except OSError as e:
65
+ if i < 2 and e.errno == 24: # too many open files
66
+ proc = psutil.Process()
67
+ t = 0.1 * len(proc.open_files())
68
+ if context_vars["async"]:
69
+ await asyncio.sleep(t)
70
+ else:
71
+ time.sleep(t)
75
72
  else:
76
73
  raise
77
74
 
mt/asyncio/__init__.py ADDED
@@ -0,0 +1,44 @@
1
+ """Alias module of asyncio.
2
+
3
+ Instead of:
4
+
5
+ .. code-block:: python
6
+
7
+ import asyncio
8
+
9
+ You do:
10
+
11
+ .. code-block:: python
12
+
13
+ from mt import mpl
14
+
15
+ It will import the asyncio package.
16
+
17
+ As of 2025-06-04, apart from importing the asyncio package, it ensures that TaskGroup, Runner and
18
+ timeout components of asyncio exist, even for Python version 3.10, by importing the backport
19
+ package called `taskgroup`.
20
+
21
+ Please see Python package `asyncio`_ for more details.
22
+
23
+ .. _asyncio:
24
+ https://docs.python.org/3/library/asyncio.html
25
+ """
26
+
27
+ import sys
28
+ from asyncio import *
29
+ from asyncio import __version__
30
+
31
+ import asyncio as _asyncio
32
+
33
+ for key in _asyncio.__dict__:
34
+ if key == "__doc__":
35
+ continue
36
+ globals()[key] = _asyncio.__dict__[key]
37
+
38
+ if sys.python_version < (3, 11):
39
+ try:
40
+ from taskgroup import run, TaskGroup, timeout
41
+ except ImportError:
42
+ raise ImportError(
43
+ f"For python version {sys.python_version}, mt.asyncio relies on asyncio.timeout of Python 3.12, please install package 'taskgroup'."
44
+ )
mt/base/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 4
2
2
  MINOR_VERSION = 32
3
- PATCH_VERSION = 26
3
+ PATCH_VERSION = 28
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtbase
3
- Version: 4.32.26
3
+ Version: 4.32.28
4
4
  Summary: The most fundamental Python modules for Minh-Tri Pham
5
5
  Home-page: https://github.com/inteplus/mtbase
6
6
  Author: ['Minh-Tri Pham']
@@ -1,9 +1,10 @@
1
1
  mt/aio/__init__.py,sha256=-k13vDemo1Onk3yPWv86zav4HAnimvLVpXdH2mkXRJc,2202
2
2
  mt/aio/base.py,sha256=HE97hmtjHcxA2t_gd4AZ4e5mlRd4lIGY5jY_f65pdPg,3982
3
- mt/aio/files.py,sha256=0J-3BevUzMP5VmnfBUnJqYbB3MQYPCOSbO0ygLoz5hI,13937
3
+ mt/aio/files.py,sha256=tjF4kBsrZ35Jon_UfE0nCN3CiQFddZFNDOvXAKUmlDk,13835
4
4
  mt/aio/multiprocessing.py,sha256=G43P7bN10J7UqTYCsa1eh3VatJWEbLEqg1xNK3MKWdk,8978
5
5
  mt/aio/path.py,sha256=d-zE88pTD65-KskLi6j_1Hdys7NXrDOOmHqUyHYxehY,10041
6
6
  mt/aio/procedure.py,sha256=eJ4AtCxqvDDxGrz-Pycred1CJRfD60VPvjUaaJ0OhYM,3323
7
+ mt/asyncio/__init__.py,sha256=2kmwgBJz8deOAYP-gEwdVbpDG4U5x2omwH0-d54--rA,1011
7
8
  mt/base/__init__.py,sha256=LUzWBMDVFvn-p1EJrt8PVXSBsZL9KHaosjIDTmYROsY,1738
8
9
  mt/base/bg_invoke.py,sha256=leV0EfoOmkuJp_FuvKc3XEBmxAOBFNLkPY6YuhQO7sQ,15828
9
10
  mt/base/casting.py,sha256=yHmHDzISEsarasHQXg6MmqNYuxt1Ab4MYj8Okh2-oN8,2471
@@ -24,7 +25,7 @@ mt/base/s3.py,sha256=dt-ph2pBv2oplddlRHCkbP58i4P-g60US6DhC4vAKAA,20083
24
25
  mt/base/str.py,sha256=_R1GRJG8XEfUwabz_dsMD-g0zf3bF4b41_L3vXmiI0o,3580
25
26
  mt/base/terminal.py,sha256=_23Kk7oihgCbe2yjJw2SQrTCqymSi-drejn1SWIS6IY,104
26
27
  mt/base/threading.py,sha256=MTVjpaTg_sbZWCksoP_5iMVYFjjUxrgpYBMOWxFY4Ms,110
27
- mt/base/version.py,sha256=Zan_moqEuHmlxhycJJ7rHP0HalhSd-kFuuSsTaszxaw,208
28
+ mt/base/version.py,sha256=jsTifl0EGZgNx8TtNoroBBrujKXKhvzmy5_hocHnIoM,208
28
29
  mt/base/zipfile.py,sha256=SnsBCaPlPw300_mi7WYB6wSqjvW-U_g96vS2S9JwrnE,1765
29
30
  mt/concurrency/__init__.py,sha256=jF7NoWRKap-QhuJaJZ3EUpfrn2HaZa_8MAS0bT325AY,428
30
31
  mt/concurrency/aio.py,sha256=efStmaQ6JkqdS7fQTcvCmOVH3ylqyKsEG8tjXhZQIZs,24785
@@ -57,9 +58,9 @@ mt/time/__init__.py,sha256=lAjC0En0X0spHTu2YC120AchNlv1SzHgQlX0RmXWLEc,2158
57
58
  mt/tp/__init__.py,sha256=TvEzpRQpi8eKdt-mGhX6mgkY3V4zB-0RWNf-BiRm1vU,633
58
59
  mt/traceback/__init__.py,sha256=4WUtGbPklLM9s-jlQQrQiFuEaTbKQKeV1DEzRj_HfYY,3648
59
60
  mt/v4l2/__init__.py,sha256=s5a0Ve3QI0I2F2q192qLKfw8dPvcrHRy1JCdpMQz8cE,870
60
- mtbase-4.32.26.data/scripts/path_exists,sha256=9rYAZNiVEeTTi-hKM8NkQVIZOaEQkWE_WVw72avfUDo,690
61
- mtbase-4.32.26.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
62
- mtbase-4.32.26.dist-info/METADATA,sha256=8pzqld5jVNOPF_IonWD6jZrRRPNFpxe9LEq9Qk6m6bU,806
63
- mtbase-4.32.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
64
- mtbase-4.32.26.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
65
- mtbase-4.32.26.dist-info/RECORD,,
61
+ mtbase-4.32.28.data/scripts/path_exists,sha256=9rYAZNiVEeTTi-hKM8NkQVIZOaEQkWE_WVw72avfUDo,690
62
+ mtbase-4.32.28.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
63
+ mtbase-4.32.28.dist-info/METADATA,sha256=hJBNGz9Fjl97O2liwo0eabqEuhgOXTA-QBbPq688FLQ,806
64
+ mtbase-4.32.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
+ mtbase-4.32.28.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
66
+ mtbase-4.32.28.dist-info/RECORD,,