ez-a-sync 0.32.29__cp310-cp310-win_amd64.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 +42 -0
- a_sync/__init__.pxd +2 -0
- a_sync/__init__.py +145 -0
- a_sync/_smart.c +22803 -0
- a_sync/_smart.cp310-win_amd64.pyd +0 -0
- a_sync/_smart.pxd +2 -0
- a_sync/_smart.pyi +202 -0
- a_sync/_smart.pyx +674 -0
- a_sync/_typing.py +258 -0
- a_sync/a_sync/__init__.py +60 -0
- a_sync/a_sync/_descriptor.c +20528 -0
- a_sync/a_sync/_descriptor.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_descriptor.pyi +33 -0
- a_sync/a_sync/_descriptor.pyx +422 -0
- a_sync/a_sync/_flags.c +6074 -0
- a_sync/a_sync/_flags.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_flags.pxd +3 -0
- a_sync/a_sync/_flags.pyx +92 -0
- a_sync/a_sync/_helpers.c +14521 -0
- a_sync/a_sync/_helpers.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_helpers.pxd +3 -0
- a_sync/a_sync/_helpers.pyi +10 -0
- a_sync/a_sync/_helpers.pyx +167 -0
- a_sync/a_sync/_kwargs.c +12194 -0
- a_sync/a_sync/_kwargs.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/_kwargs.pxd +2 -0
- a_sync/a_sync/_kwargs.pyx +64 -0
- a_sync/a_sync/_meta.py +210 -0
- a_sync/a_sync/abstract.c +12411 -0
- a_sync/a_sync/abstract.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/abstract.pyi +141 -0
- a_sync/a_sync/abstract.pyx +221 -0
- a_sync/a_sync/base.c +14932 -0
- a_sync/a_sync/base.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/base.pyi +60 -0
- a_sync/a_sync/base.pyx +271 -0
- a_sync/a_sync/config.py +168 -0
- a_sync/a_sync/decorator.py +651 -0
- a_sync/a_sync/flags.c +5272 -0
- a_sync/a_sync/flags.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/flags.pxd +72 -0
- a_sync/a_sync/flags.pyi +74 -0
- a_sync/a_sync/flags.pyx +72 -0
- a_sync/a_sync/function.c +37846 -0
- a_sync/a_sync/function.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/function.pxd +28 -0
- a_sync/a_sync/function.pyi +571 -0
- a_sync/a_sync/function.pyx +1381 -0
- a_sync/a_sync/method.c +29774 -0
- a_sync/a_sync/method.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/method.pxd +9 -0
- a_sync/a_sync/method.pyi +525 -0
- a_sync/a_sync/method.pyx +1023 -0
- a_sync/a_sync/modifiers/__init__.pxd +1 -0
- a_sync/a_sync/modifiers/__init__.py +101 -0
- a_sync/a_sync/modifiers/cache/__init__.py +160 -0
- a_sync/a_sync/modifiers/cache/memory.py +165 -0
- a_sync/a_sync/modifiers/limiter.py +132 -0
- a_sync/a_sync/modifiers/manager.c +16149 -0
- a_sync/a_sync/modifiers/manager.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/modifiers/manager.pxd +5 -0
- a_sync/a_sync/modifiers/manager.pyi +219 -0
- a_sync/a_sync/modifiers/manager.pyx +299 -0
- a_sync/a_sync/modifiers/semaphores.py +173 -0
- a_sync/a_sync/property.c +27260 -0
- a_sync/a_sync/property.cp310-win_amd64.pyd +0 -0
- a_sync/a_sync/property.pyi +376 -0
- a_sync/a_sync/property.pyx +819 -0
- a_sync/a_sync/singleton.py +63 -0
- a_sync/aliases.py +3 -0
- a_sync/async_property/__init__.pxd +1 -0
- a_sync/async_property/__init__.py +1 -0
- a_sync/async_property/cached.c +20386 -0
- a_sync/async_property/cached.cp310-win_amd64.pyd +0 -0
- a_sync/async_property/cached.pxd +10 -0
- a_sync/async_property/cached.pyi +45 -0
- a_sync/async_property/cached.pyx +178 -0
- a_sync/async_property/proxy.c +34654 -0
- a_sync/async_property/proxy.cp310-win_amd64.pyd +0 -0
- a_sync/async_property/proxy.pxd +2 -0
- a_sync/async_property/proxy.pyi +124 -0
- a_sync/async_property/proxy.pyx +474 -0
- a_sync/asyncio/__init__.pxd +6 -0
- a_sync/asyncio/__init__.py +164 -0
- a_sync/asyncio/as_completed.c +18841 -0
- a_sync/asyncio/as_completed.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/as_completed.pxd +8 -0
- a_sync/asyncio/as_completed.pyi +109 -0
- a_sync/asyncio/as_completed.pyx +269 -0
- a_sync/asyncio/create_task.c +15902 -0
- a_sync/asyncio/create_task.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/create_task.pxd +2 -0
- a_sync/asyncio/create_task.pyi +51 -0
- a_sync/asyncio/create_task.pyx +271 -0
- a_sync/asyncio/gather.c +16679 -0
- a_sync/asyncio/gather.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/gather.pyi +107 -0
- a_sync/asyncio/gather.pyx +218 -0
- a_sync/asyncio/igather.c +12676 -0
- a_sync/asyncio/igather.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/igather.pxd +1 -0
- a_sync/asyncio/igather.pyi +7 -0
- a_sync/asyncio/igather.pyx +182 -0
- a_sync/asyncio/sleep.c +9593 -0
- a_sync/asyncio/sleep.cp310-win_amd64.pyd +0 -0
- a_sync/asyncio/sleep.pyi +14 -0
- a_sync/asyncio/sleep.pyx +49 -0
- a_sync/debugging.c +15362 -0
- a_sync/debugging.cp310-win_amd64.pyd +0 -0
- a_sync/debugging.pyi +76 -0
- a_sync/debugging.pyx +107 -0
- a_sync/exceptions.c +13312 -0
- a_sync/exceptions.cp310-win_amd64.pyd +0 -0
- a_sync/exceptions.pyi +376 -0
- a_sync/exceptions.pyx +446 -0
- a_sync/executor.py +619 -0
- a_sync/functools.c +12738 -0
- a_sync/functools.cp310-win_amd64.pyd +0 -0
- a_sync/functools.pxd +7 -0
- a_sync/functools.pyi +33 -0
- a_sync/functools.pyx +139 -0
- a_sync/future.py +1497 -0
- a_sync/iter.c +37271 -0
- a_sync/iter.cp310-win_amd64.pyd +0 -0
- a_sync/iter.pxd +11 -0
- a_sync/iter.pyi +370 -0
- a_sync/iter.pyx +981 -0
- a_sync/primitives/__init__.pxd +1 -0
- a_sync/primitives/__init__.py +53 -0
- a_sync/primitives/_debug.c +15757 -0
- a_sync/primitives/_debug.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/_debug.pxd +12 -0
- a_sync/primitives/_debug.pyi +52 -0
- a_sync/primitives/_debug.pyx +223 -0
- a_sync/primitives/_loggable.c +11529 -0
- a_sync/primitives/_loggable.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/_loggable.pxd +4 -0
- a_sync/primitives/_loggable.pyi +66 -0
- a_sync/primitives/_loggable.pyx +102 -0
- a_sync/primitives/locks/__init__.pxd +8 -0
- a_sync/primitives/locks/__init__.py +17 -0
- a_sync/primitives/locks/counter.c +17679 -0
- a_sync/primitives/locks/counter.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/counter.pxd +12 -0
- a_sync/primitives/locks/counter.pyi +151 -0
- a_sync/primitives/locks/counter.pyx +260 -0
- a_sync/primitives/locks/event.c +17063 -0
- a_sync/primitives/locks/event.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/event.pxd +22 -0
- a_sync/primitives/locks/event.pyi +43 -0
- a_sync/primitives/locks/event.pyx +185 -0
- a_sync/primitives/locks/prio_semaphore.c +25590 -0
- a_sync/primitives/locks/prio_semaphore.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/prio_semaphore.pxd +25 -0
- a_sync/primitives/locks/prio_semaphore.pyi +217 -0
- a_sync/primitives/locks/prio_semaphore.pyx +597 -0
- a_sync/primitives/locks/semaphore.c +26509 -0
- a_sync/primitives/locks/semaphore.cp310-win_amd64.pyd +0 -0
- a_sync/primitives/locks/semaphore.pxd +21 -0
- a_sync/primitives/locks/semaphore.pyi +197 -0
- a_sync/primitives/locks/semaphore.pyx +454 -0
- a_sync/primitives/queue.py +1022 -0
- a_sync/py.typed +0 -0
- a_sync/sphinx/__init__.py +3 -0
- a_sync/sphinx/ext.py +289 -0
- a_sync/task.py +932 -0
- a_sync/utils/__init__.py +105 -0
- a_sync/utils/iterators.py +297 -0
- a_sync/utils/repr.c +15799 -0
- a_sync/utils/repr.cp310-win_amd64.pyd +0 -0
- a_sync/utils/repr.pyi +2 -0
- a_sync/utils/repr.pyx +73 -0
- ez_a_sync-0.32.29.dist-info/METADATA +367 -0
- ez_a_sync-0.32.29.dist-info/RECORD +177 -0
- ez_a_sync-0.32.29.dist-info/WHEEL +5 -0
- ez_a_sync-0.32.29.dist-info/licenses/LICENSE.txt +17 -0
- ez_a_sync-0.32.29.dist-info/top_level.txt +1 -0
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides utility functions for handling asynchronous operations
|
|
3
|
+
and converting synchronous functions to asynchronous ones.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from a_sync._typing import *
|
|
7
|
+
from a_sync import exceptions as exceptions
|
|
8
|
+
|
|
9
|
+
def get_event_loop() -> asyncio.AbstractEventLoop: ...
|
|
10
|
+
def _await(awaitable: Awaitable[T]) -> T: ...
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides utility functions for handling asynchronous operations
|
|
3
|
+
and converting synchronous functions to asynchronous ones.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import asyncio.futures as aiofutures
|
|
8
|
+
from concurrent.futures import Executor
|
|
9
|
+
|
|
10
|
+
cimport cython
|
|
11
|
+
|
|
12
|
+
from a_sync import exceptions
|
|
13
|
+
from a_sync._typing import P, T
|
|
14
|
+
from a_sync.a_sync.function cimport _ASyncFunction
|
|
15
|
+
from a_sync.executor import _AsyncExecutorMixin
|
|
16
|
+
from a_sync.functools cimport wraps
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# cdef asyncio
|
|
20
|
+
cdef object iscoroutinefunction = asyncio.iscoroutinefunction
|
|
21
|
+
cdef object get_running_loop = asyncio.get_running_loop
|
|
22
|
+
cdef object new_event_loop = asyncio.new_event_loop
|
|
23
|
+
cdef object set_event_loop = asyncio.set_event_loop
|
|
24
|
+
cdef object _chain_future = aiofutures._chain_future
|
|
25
|
+
cdef object _get_event_loop = asyncio.get_event_loop
|
|
26
|
+
del asyncio, aiofutures
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# cdef exceptions
|
|
30
|
+
cdef object FunctionNotSync = exceptions.FunctionNotSync
|
|
31
|
+
cdef object SyncModeInAsyncContextError = exceptions.SyncModeInAsyncContextError
|
|
32
|
+
del exceptions
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@cython.profile(False)
|
|
36
|
+
@cython.linetrace(False)
|
|
37
|
+
cpdef inline object get_event_loop():
|
|
38
|
+
cdef object loop
|
|
39
|
+
try:
|
|
40
|
+
return _get_event_loop()
|
|
41
|
+
except RuntimeError as e: # Necessary for use with multi-threaded applications.
|
|
42
|
+
if not str(e).startswith("There is no current event loop in thread"):
|
|
43
|
+
raise
|
|
44
|
+
loop = new_event_loop()
|
|
45
|
+
set_event_loop(loop)
|
|
46
|
+
return loop
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@cython.profile(False)
|
|
50
|
+
@cython.linetrace(False)
|
|
51
|
+
cdef object _await(object awaitable):
|
|
52
|
+
"""
|
|
53
|
+
Await an awaitable object in a synchronous context.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
awaitable (Awaitable[T]): The awaitable object to be awaited.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
exceptions.SyncModeInAsyncContextError: If the event loop is already running.
|
|
60
|
+
|
|
61
|
+
Examples:
|
|
62
|
+
>>> async def example_coroutine():
|
|
63
|
+
... return 42
|
|
64
|
+
...
|
|
65
|
+
>>> result = _await(example_coroutine())
|
|
66
|
+
>>> print(result)
|
|
67
|
+
42
|
|
68
|
+
|
|
69
|
+
See Also:
|
|
70
|
+
- :func:`asyncio.run`: For running the main entry point of an asyncio program.
|
|
71
|
+
"""
|
|
72
|
+
try:
|
|
73
|
+
return get_event_loop().run_until_complete(awaitable)
|
|
74
|
+
except RuntimeError as e:
|
|
75
|
+
if str(e) == "This event loop is already running":
|
|
76
|
+
raise SyncModeInAsyncContextError from None
|
|
77
|
+
raise
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
cdef object _asyncify(object func, executor: Executor): # type: ignore [misc]
|
|
81
|
+
"""
|
|
82
|
+
Convert a synchronous function to a coroutine function using an executor.
|
|
83
|
+
|
|
84
|
+
This function submits the synchronous function to the provided executor and wraps
|
|
85
|
+
the resulting future in a coroutine function. This allows the synchronous function
|
|
86
|
+
to be executed asynchronously.
|
|
87
|
+
|
|
88
|
+
Note:
|
|
89
|
+
The function `_asyncify` uses `asyncio.futures.wrap_future` to wrap the future
|
|
90
|
+
returned by the executor, specifying the event loop with `a_sync.asyncio.get_event_loop()`.
|
|
91
|
+
Ensure that your environment supports this usage or adjust the import if necessary.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
func (SyncFn[P, T]): The synchronous function to be converted.
|
|
95
|
+
executor (Executor): The executor used to run the synchronous function.
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
exceptions.FunctionNotSync: If the input function is a coroutine function or an instance of :class:`~a_sync.a_sync.function.ASyncFunction`.
|
|
99
|
+
|
|
100
|
+
Examples:
|
|
101
|
+
>>> from concurrent.futures import ThreadPoolExecutor
|
|
102
|
+
>>> def sync_function(x):
|
|
103
|
+
... return x * 2
|
|
104
|
+
...
|
|
105
|
+
>>> executor = ThreadPoolExecutor()
|
|
106
|
+
>>> async_function = _asyncify(sync_function, executor)
|
|
107
|
+
>>> result = await async_function(3)
|
|
108
|
+
>>> print(result)
|
|
109
|
+
6
|
|
110
|
+
|
|
111
|
+
See Also:
|
|
112
|
+
- :class:`concurrent.futures.Executor`: For managing pools of threads or processes.
|
|
113
|
+
- :func:`asyncio.to_thread`: For running blocking code in a separate thread.
|
|
114
|
+
"""
|
|
115
|
+
if iscoroutinefunction(func) or isinstance(func, _ASyncFunction):
|
|
116
|
+
raise FunctionNotSync(func)
|
|
117
|
+
|
|
118
|
+
if isinstance(executor, _AsyncExecutorMixin):
|
|
119
|
+
# ASyncExecutor classes are better optimized.
|
|
120
|
+
# TODO: implement the same optimizations in the else block below
|
|
121
|
+
return _asyncify_with_a_sync_executor(func, executor)
|
|
122
|
+
|
|
123
|
+
else:
|
|
124
|
+
return _asyncify_with_cf_executor(func, executor)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
cdef object _asyncify_with_a_sync_executor(object func, executor: _AsyncExecutorMixin):
|
|
128
|
+
# ASyncExecutor classes are better optimized than normal ones and we can do this
|
|
129
|
+
run = executor.run
|
|
130
|
+
|
|
131
|
+
@wraps(func)
|
|
132
|
+
async def _asyncify_wrap_fast(*args, **kwargs):
|
|
133
|
+
return await run(func, *args, **kwargs)
|
|
134
|
+
|
|
135
|
+
return _asyncify_wrap_fast
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
cdef object _asyncify_with_cf_executor(object func, executor: Executor):
|
|
139
|
+
cdef object submit
|
|
140
|
+
cdef object loop
|
|
141
|
+
cdef object create_future
|
|
142
|
+
|
|
143
|
+
submit = executor.submit
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
loop = get_running_loop()
|
|
147
|
+
create_future = loop.create_future
|
|
148
|
+
|
|
149
|
+
@wraps(func)
|
|
150
|
+
async def _asyncify_wrap(*args, **kwargs):
|
|
151
|
+
fut = create_future()
|
|
152
|
+
cf_fut = submit(func, *args, **kwargs)
|
|
153
|
+
_chain_future(cf_fut, fut)
|
|
154
|
+
return await fut
|
|
155
|
+
|
|
156
|
+
except RuntimeError:
|
|
157
|
+
loop, create_future = None, None
|
|
158
|
+
|
|
159
|
+
@wraps(func)
|
|
160
|
+
async def _asyncify_wrap(*args, **kwargs):
|
|
161
|
+
loop = get_event_loop()
|
|
162
|
+
fut = loop.create_future()
|
|
163
|
+
cf_fut = submit(func, *args, **kwargs)
|
|
164
|
+
_chain_future(cf_fut, fut)
|
|
165
|
+
return await fut
|
|
166
|
+
|
|
167
|
+
return _asyncify_wrap
|