ez-a-sync 0.22.14__py3-none-any.whl → 0.22.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.
Potentially problematic release.
This version of ez-a-sync might be problematic. Click here for more details.
- a_sync/ENVIRONMENT_VARIABLES.py +37 -5
- a_sync/__init__.py +53 -12
- a_sync/_smart.py +231 -28
- a_sync/_typing.py +112 -15
- a_sync/a_sync/__init__.py +35 -10
- a_sync/a_sync/_descriptor.py +248 -38
- a_sync/a_sync/_flags.py +78 -9
- a_sync/a_sync/_helpers.py +46 -13
- a_sync/a_sync/_kwargs.py +33 -8
- a_sync/a_sync/_meta.py +149 -28
- a_sync/a_sync/abstract.py +150 -28
- a_sync/a_sync/base.py +34 -16
- a_sync/a_sync/config.py +85 -14
- a_sync/a_sync/decorator.py +441 -139
- a_sync/a_sync/function.py +709 -147
- a_sync/a_sync/method.py +437 -110
- a_sync/a_sync/modifiers/__init__.py +85 -5
- a_sync/a_sync/modifiers/cache/__init__.py +116 -17
- a_sync/a_sync/modifiers/cache/memory.py +130 -20
- a_sync/a_sync/modifiers/limiter.py +101 -22
- a_sync/a_sync/modifiers/manager.py +142 -16
- a_sync/a_sync/modifiers/semaphores.py +121 -15
- a_sync/a_sync/property.py +383 -82
- a_sync/a_sync/singleton.py +44 -19
- a_sync/aliases.py +0 -1
- a_sync/asyncio/__init__.py +140 -1
- a_sync/asyncio/as_completed.py +213 -79
- a_sync/asyncio/create_task.py +70 -20
- a_sync/asyncio/gather.py +125 -58
- a_sync/asyncio/utils.py +3 -3
- a_sync/exceptions.py +248 -26
- a_sync/executor.py +164 -69
- a_sync/future.py +1227 -168
- a_sync/iter.py +173 -56
- a_sync/primitives/__init__.py +14 -2
- a_sync/primitives/_debug.py +72 -18
- a_sync/primitives/_loggable.py +41 -10
- a_sync/primitives/locks/__init__.py +5 -2
- a_sync/primitives/locks/counter.py +107 -38
- a_sync/primitives/locks/event.py +21 -7
- a_sync/primitives/locks/prio_semaphore.py +262 -63
- a_sync/primitives/locks/semaphore.py +138 -89
- a_sync/primitives/queue.py +601 -60
- a_sync/sphinx/__init__.py +0 -1
- a_sync/sphinx/ext.py +160 -50
- a_sync/task.py +313 -112
- a_sync/utils/__init__.py +12 -6
- a_sync/utils/iterators.py +170 -50
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/METADATA +1 -1
- ez_a_sync-0.22.16.dist-info/RECORD +74 -0
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/WHEEL +1 -1
- tests/conftest.py +1 -2
- tests/executor.py +250 -9
- tests/fixtures.py +61 -32
- tests/test_abstract.py +22 -4
- tests/test_as_completed.py +54 -21
- tests/test_base.py +264 -19
- tests/test_cache.py +31 -15
- tests/test_decorator.py +54 -28
- tests/test_executor.py +31 -13
- tests/test_future.py +45 -8
- tests/test_gather.py +8 -2
- tests/test_helpers.py +2 -0
- tests/test_iter.py +55 -13
- tests/test_limiter.py +5 -3
- tests/test_meta.py +23 -9
- tests/test_modified.py +4 -1
- tests/test_semaphore.py +15 -8
- tests/test_singleton.py +28 -11
- tests/test_task.py +162 -36
- ez_a_sync-0.22.14.dist-info/RECORD +0 -74
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/LICENSE.txt +0 -0
- {ez_a_sync-0.22.14.dist-info → ez_a_sync-0.22.16.dist-info}/top_level.txt +0 -0
a_sync/a_sync/config.py
CHANGED
|
@@ -1,9 +1,46 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Configuration module for a_sync library.
|
|
3
|
-
|
|
4
2
|
This module provides configuration options and default settings for the a_sync library.
|
|
5
3
|
It includes functionality for setting up executors, defining default modifiers,
|
|
6
4
|
and handling environment variable configurations.
|
|
5
|
+
|
|
6
|
+
Environment Variables:
|
|
7
|
+
A_SYNC_EXECUTOR_TYPE: Specifies the type of executor to use. Valid values are
|
|
8
|
+
strings that start with 'p' for :class:`~concurrent.futures.ProcessPoolExecutor`
|
|
9
|
+
(e.g., 'processes') or 't' for :class:`~concurrent.futures.ThreadPoolExecutor`
|
|
10
|
+
(e.g., 'threads'). Defaults to 'threads'.
|
|
11
|
+
A_SYNC_EXECUTOR_VALUE: Specifies the number of workers for the executor.
|
|
12
|
+
Defaults to 8.
|
|
13
|
+
A_SYNC_DEFAULT_MODE: Sets the default mode for a_sync functions if not specified.
|
|
14
|
+
A_SYNC_CACHE_TYPE: Sets the default cache type. If not specified, defaults to None.
|
|
15
|
+
A_SYNC_CACHE_TYPED: Boolean flag to determine if cache keys should consider types.
|
|
16
|
+
A_SYNC_RAM_CACHE_MAXSIZE: Sets the maximum size for the RAM cache. Defaults to -1.
|
|
17
|
+
A_SYNC_RAM_CACHE_TTL: Sets the time-to-live for cache entries. If not specified,
|
|
18
|
+
defaults to None, meaning cache entries do not expire by default.
|
|
19
|
+
Note: Although the environment variable retrieval process uses 0 as a placeholder,
|
|
20
|
+
the actual default behavior is determined by `null_modifiers["ram_cache_ttl"]`,
|
|
21
|
+
which is `None`.
|
|
22
|
+
A_SYNC_RUNS_PER_MINUTE: Sets the rate limit for function execution.
|
|
23
|
+
A_SYNC_SEMAPHORE: Sets the semaphore limit for function execution.
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
To set the executor type to use threads with 4 workers, set the environment variables:
|
|
27
|
+
|
|
28
|
+
.. code-block:: bash
|
|
29
|
+
|
|
30
|
+
export A_SYNC_EXECUTOR_TYPE=threads
|
|
31
|
+
export A_SYNC_EXECUTOR_VALUE=4
|
|
32
|
+
|
|
33
|
+
To configure caching with a maximum size of 100 and a TTL of 60 seconds:
|
|
34
|
+
|
|
35
|
+
.. code-block:: bash
|
|
36
|
+
|
|
37
|
+
export A_SYNC_CACHE_TYPE=memory
|
|
38
|
+
export A_SYNC_RAM_CACHE_MAXSIZE=100
|
|
39
|
+
export A_SYNC_RAM_CACHE_TTL=60
|
|
40
|
+
|
|
41
|
+
See Also:
|
|
42
|
+
- :mod:`concurrent.futures`: For more details on executors.
|
|
43
|
+
- :mod:`functools`: For caching mechanisms.
|
|
7
44
|
"""
|
|
8
45
|
|
|
9
46
|
import functools
|
|
@@ -16,22 +53,40 @@ from a_sync._typing import *
|
|
|
16
53
|
EXECUTOR_TYPE = os.environ.get("A_SYNC_EXECUTOR_TYPE", "threads")
|
|
17
54
|
EXECUTOR_VALUE = int(os.environ.get("A_SYNC_EXECUTOR_VALUE", 8))
|
|
18
55
|
|
|
56
|
+
|
|
19
57
|
@functools.lru_cache(maxsize=1)
|
|
20
58
|
def get_default_executor() -> Executor:
|
|
21
|
-
"""
|
|
22
|
-
Get the default executor based on the :obj:`EXECUTOR_TYPE` environment variable.
|
|
59
|
+
"""Get the default executor based on the EXECUTOR_TYPE environment variable.
|
|
23
60
|
|
|
24
61
|
Returns:
|
|
25
|
-
|
|
62
|
+
An instance of either :class:`~concurrent.futures.ProcessPoolExecutor`
|
|
63
|
+
or :class:`~concurrent.futures.ThreadPoolExecutor`.
|
|
26
64
|
|
|
27
65
|
Raises:
|
|
28
|
-
:
|
|
66
|
+
ValueError: If an invalid EXECUTOR_TYPE is specified. Valid values are
|
|
67
|
+
strings that start with 'p' for :class:`~concurrent.futures.ProcessPoolExecutor`
|
|
68
|
+
or 't' for :class:`~concurrent.futures.ThreadPoolExecutor`.
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
>>> import os
|
|
72
|
+
>>> os.environ["A_SYNC_EXECUTOR_TYPE"] = "threads"
|
|
73
|
+
>>> executor = get_default_executor()
|
|
74
|
+
>>> isinstance(executor, ThreadPoolExecutor)
|
|
75
|
+
True
|
|
76
|
+
|
|
77
|
+
>>> os.environ["A_SYNC_EXECUTOR_TYPE"] = "processes"
|
|
78
|
+
>>> executor = get_default_executor()
|
|
79
|
+
>>> isinstance(executor, ProcessPoolExecutor)
|
|
80
|
+
True
|
|
29
81
|
"""
|
|
30
|
-
if EXECUTOR_TYPE.lower().startswith(
|
|
82
|
+
if EXECUTOR_TYPE.lower().startswith("p"): # p, P, proc, Processes, etc
|
|
31
83
|
return ProcessPoolExecutor(EXECUTOR_VALUE)
|
|
32
|
-
elif EXECUTOR_TYPE.lower().startswith(
|
|
84
|
+
elif EXECUTOR_TYPE.lower().startswith("t"): # t, T, thread, THREADS, etc
|
|
33
85
|
return ThreadPoolExecutor(EXECUTOR_VALUE)
|
|
34
|
-
raise ValueError(
|
|
86
|
+
raise ValueError(
|
|
87
|
+
"Invalid value for A_SYNC_EXECUTOR_TYPE. Please use 'threads' or 'processes'."
|
|
88
|
+
)
|
|
89
|
+
|
|
35
90
|
|
|
36
91
|
default_sync_executor = get_default_executor()
|
|
37
92
|
|
|
@@ -53,13 +108,29 @@ null_modifiers = ModifierKwargs(
|
|
|
53
108
|
# User configurable default modifiers to be applied to any a_sync decorated function if you do not specify kwarg values for each modifier.
|
|
54
109
|
|
|
55
110
|
DEFAULT_MODE: DefaultMode = os.environ.get("A_SYNC_DEFAULT_MODE") # type: ignore [assignment]
|
|
56
|
-
CACHE_TYPE: CacheType =
|
|
111
|
+
CACHE_TYPE: CacheType = (
|
|
112
|
+
typ
|
|
113
|
+
if (typ := os.environ.get("A_SYNC_CACHE_TYPE", "").lower())
|
|
114
|
+
else null_modifiers["cache_type"]
|
|
115
|
+
)
|
|
57
116
|
CACHE_TYPED = bool(os.environ.get("A_SYNC_CACHE_TYPED"))
|
|
58
|
-
RAM_CACHE_MAXSIZE = int(os.environ.get("A_SYNC_RAM_CACHE_MAXSIZE", -1))
|
|
59
|
-
RAM_CACHE_TTL =
|
|
117
|
+
RAM_CACHE_MAXSIZE = int(os.environ.get("A_SYNC_RAM_CACHE_MAXSIZE", -1))
|
|
118
|
+
RAM_CACHE_TTL = (
|
|
119
|
+
ttl
|
|
120
|
+
if (ttl := float(os.environ.get("A_SYNC_RAM_CACHE_TTL", 0)))
|
|
121
|
+
else null_modifiers["ram_cache_ttl"]
|
|
122
|
+
)
|
|
60
123
|
|
|
61
|
-
RUNS_PER_MINUTE =
|
|
62
|
-
|
|
124
|
+
RUNS_PER_MINUTE = (
|
|
125
|
+
rpm
|
|
126
|
+
if (rpm := int(os.environ.get("A_SYNC_RUNS_PER_MINUTE", 0)))
|
|
127
|
+
else null_modifiers["runs_per_minute"]
|
|
128
|
+
)
|
|
129
|
+
SEMAPHORE = (
|
|
130
|
+
rpm
|
|
131
|
+
if (rpm := int(os.environ.get("A_SYNC_SEMAPHORE", 0)))
|
|
132
|
+
else null_modifiers["semaphore"]
|
|
133
|
+
)
|
|
63
134
|
|
|
64
135
|
user_set_default_modifiers = ModifierKwargs(
|
|
65
136
|
default=DEFAULT_MODE,
|