ez-a-sync 0.32.29__cp310-cp310-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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-win32.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,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module extends Python's :func:`asyncio.as_completed` with additional functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from a_sync._typing import *
|
|
6
|
+
from a_sync.iter import ASyncIterator
|
|
7
|
+
|
|
8
|
+
__all__ = ["as_completed"]
|
|
9
|
+
|
|
10
|
+
class tqdm_asyncio:
|
|
11
|
+
@staticmethod
|
|
12
|
+
def as_completed(*args, **kwargs) -> None: ...
|
|
13
|
+
|
|
14
|
+
@overload
|
|
15
|
+
def as_completed(
|
|
16
|
+
fs: Iterable[Awaitable[T]],
|
|
17
|
+
*,
|
|
18
|
+
timeout: Optional[float] = None,
|
|
19
|
+
return_exceptions: bool = False,
|
|
20
|
+
aiter: Literal[False] = False,
|
|
21
|
+
tqdm: bool = False,
|
|
22
|
+
**tqdm_kwargs: Any
|
|
23
|
+
) -> Iterator[Coroutine[Any, Any, T]]: ...
|
|
24
|
+
@overload
|
|
25
|
+
def as_completed(
|
|
26
|
+
fs: Iterable[Awaitable[T]],
|
|
27
|
+
*,
|
|
28
|
+
timeout: Optional[float] = None,
|
|
29
|
+
return_exceptions: bool = False,
|
|
30
|
+
aiter: Literal[True] = True,
|
|
31
|
+
tqdm: bool = False,
|
|
32
|
+
**tqdm_kwargs: Any
|
|
33
|
+
) -> ASyncIterator[T]: ...
|
|
34
|
+
@overload
|
|
35
|
+
def as_completed(
|
|
36
|
+
fs: Mapping[K, Awaitable[V]],
|
|
37
|
+
*,
|
|
38
|
+
timeout: Optional[float] = None,
|
|
39
|
+
return_exceptions: bool = False,
|
|
40
|
+
aiter: Literal[False] = False,
|
|
41
|
+
tqdm: bool = False,
|
|
42
|
+
**tqdm_kwargs: Any
|
|
43
|
+
) -> Iterator[Coroutine[Any, Any, Tuple[K, V]]]: ...
|
|
44
|
+
@overload
|
|
45
|
+
def as_completed(
|
|
46
|
+
fs: Mapping[K, Awaitable[V]],
|
|
47
|
+
*,
|
|
48
|
+
timeout: Optional[float] = None,
|
|
49
|
+
return_exceptions: bool = False,
|
|
50
|
+
aiter: Literal[True] = True,
|
|
51
|
+
tqdm: bool = False,
|
|
52
|
+
**tqdm_kwargs: Any
|
|
53
|
+
) -> ASyncIterator[Tuple[K, V]]: ...
|
|
54
|
+
def as_completed(
|
|
55
|
+
fs,
|
|
56
|
+
*,
|
|
57
|
+
timeout: Optional[float] = None,
|
|
58
|
+
return_exceptions: bool = False,
|
|
59
|
+
aiter: bool = False,
|
|
60
|
+
tqdm: bool = False,
|
|
61
|
+
**tqdm_kwargs: Any
|
|
62
|
+
):
|
|
63
|
+
"""
|
|
64
|
+
Concurrently awaits a list of awaitable objects or mappings of awaitables and returns an iterator of results.
|
|
65
|
+
|
|
66
|
+
This function extends Python's :func:`asyncio.as_completed`, providing additional features for mixed use cases of individual awaitable objects and mappings of awaitables.
|
|
67
|
+
|
|
68
|
+
Differences from :func:`asyncio.as_completed`:
|
|
69
|
+
- Uses type hints for use with static type checkers.
|
|
70
|
+
- Supports either individual awaitables or a k:v mapping of awaitables.
|
|
71
|
+
- Can be used as an async iterator which yields the result values using :class:`ASyncIterator`.
|
|
72
|
+
- Provides progress reporting using :mod:`tqdm` if 'tqdm' is set to True.
|
|
73
|
+
|
|
74
|
+
Note:
|
|
75
|
+
The `return_exceptions` parameter is used to wrap awaitables with exceptions if set to True, allowing exceptions to be returned as results instead of being raised.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
fs: The awaitables to await concurrently. It can be a list of individual awaitables or a mapping of awaitables.
|
|
79
|
+
timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
|
|
80
|
+
return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
|
|
81
|
+
aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
|
|
82
|
+
tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
|
|
83
|
+
**tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
|
|
84
|
+
|
|
85
|
+
Examples:
|
|
86
|
+
Awaiting individual awaitables:
|
|
87
|
+
|
|
88
|
+
>>> awaitables = [async_function1(), async_function2()]
|
|
89
|
+
>>> for coro in as_completed(awaitables):
|
|
90
|
+
... val = await coro
|
|
91
|
+
... ...
|
|
92
|
+
|
|
93
|
+
>>> async for val in as_completed(awaitables, aiter=True):
|
|
94
|
+
... ...
|
|
95
|
+
|
|
96
|
+
Awaiting mappings of awaitables:
|
|
97
|
+
|
|
98
|
+
>>> mapping = {'key1': async_function1(), 'key2': async_function2()}
|
|
99
|
+
>>> for coro in as_completed(mapping):
|
|
100
|
+
... k, v = await coro
|
|
101
|
+
... ...
|
|
102
|
+
|
|
103
|
+
>>> async for k, v in as_completed(mapping, aiter=True):
|
|
104
|
+
... ...
|
|
105
|
+
|
|
106
|
+
See Also:
|
|
107
|
+
- :func:`asyncio.as_completed`
|
|
108
|
+
- :class:`ASyncIterator`
|
|
109
|
+
"""
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module extends Python's :func:`asyncio.as_completed` with additional functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from typing import (Any, AsyncIterator, Awaitable, Coroutine, Iterable,
|
|
7
|
+
Iterator, Literal, Mapping, Optional, Tuple, Union,
|
|
8
|
+
overload)
|
|
9
|
+
|
|
10
|
+
from a_sync import iter
|
|
11
|
+
from a_sync._typing import K, T, V
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# cdef asyncio
|
|
15
|
+
cdef object _as_completed = asyncio.as_completed
|
|
16
|
+
del asyncio
|
|
17
|
+
|
|
18
|
+
# cdef tqdm
|
|
19
|
+
try:
|
|
20
|
+
from tqdm.asyncio import tqdm_asyncio
|
|
21
|
+
except ImportError as e:
|
|
22
|
+
|
|
23
|
+
class tqdm_asyncio: # type: ignore [no-redef]
|
|
24
|
+
@staticmethod
|
|
25
|
+
def as_completed(*args, **kwargs):
|
|
26
|
+
raise ImportError("You must have tqdm installed to use this feature")
|
|
27
|
+
|
|
28
|
+
cdef object _tqdm_as_completed = tqdm_asyncio.as_completed
|
|
29
|
+
del tqdm_asyncio
|
|
30
|
+
|
|
31
|
+
# cdef iter
|
|
32
|
+
cdef object ASyncIterator = iter.ASyncIterator
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@overload
|
|
36
|
+
def as_completed(
|
|
37
|
+
fs: Iterable[Awaitable[T]],
|
|
38
|
+
*,
|
|
39
|
+
timeout: Optional[float] = None,
|
|
40
|
+
return_exceptions: bool = False,
|
|
41
|
+
aiter: Literal[False] = False,
|
|
42
|
+
tqdm: bool = False,
|
|
43
|
+
**tqdm_kwargs: Any
|
|
44
|
+
) -> Iterator[Coroutine[Any, Any, T]]: ...
|
|
45
|
+
@overload
|
|
46
|
+
def as_completed(
|
|
47
|
+
fs: Iterable[Awaitable[T]],
|
|
48
|
+
*,
|
|
49
|
+
timeout: Optional[float] = None,
|
|
50
|
+
return_exceptions: bool = False,
|
|
51
|
+
aiter: Literal[True] = True,
|
|
52
|
+
tqdm: bool = False,
|
|
53
|
+
**tqdm_kwargs: Any
|
|
54
|
+
) -> ASyncIterator[T]: ...
|
|
55
|
+
@overload
|
|
56
|
+
def as_completed(
|
|
57
|
+
fs: Mapping[K, Awaitable[V]],
|
|
58
|
+
*,
|
|
59
|
+
timeout: Optional[float] = None,
|
|
60
|
+
return_exceptions: bool = False,
|
|
61
|
+
aiter: Literal[False] = False,
|
|
62
|
+
tqdm: bool = False,
|
|
63
|
+
**tqdm_kwargs: Any
|
|
64
|
+
) -> Iterator[Coroutine[Any, Any, Tuple[K, V]]]: ...
|
|
65
|
+
@overload
|
|
66
|
+
def as_completed(
|
|
67
|
+
fs: Mapping[K, Awaitable[V]],
|
|
68
|
+
*,
|
|
69
|
+
timeout: Optional[float] = None,
|
|
70
|
+
return_exceptions: bool = False,
|
|
71
|
+
aiter: Literal[True] = True,
|
|
72
|
+
tqdm: bool = False,
|
|
73
|
+
**tqdm_kwargs: Any
|
|
74
|
+
) -> ASyncIterator[Tuple[K, V]]: ...
|
|
75
|
+
def as_completed(
|
|
76
|
+
fs,
|
|
77
|
+
*,
|
|
78
|
+
timeout: Optional[float] = None,
|
|
79
|
+
return_exceptions: bool = False,
|
|
80
|
+
aiter: bool = False,
|
|
81
|
+
tqdm: bool = False,
|
|
82
|
+
**tqdm_kwargs: Any
|
|
83
|
+
):
|
|
84
|
+
"""
|
|
85
|
+
Concurrently awaits a list of awaitable objects or mappings of awaitables and returns an iterator of results.
|
|
86
|
+
|
|
87
|
+
This function extends Python's :func:`asyncio.as_completed`, providing additional features for mixed use cases of individual awaitable objects and mappings of awaitables.
|
|
88
|
+
|
|
89
|
+
Differences from :func:`asyncio.as_completed`:
|
|
90
|
+
- Uses type hints for use with static type checkers.
|
|
91
|
+
- Supports either individual awaitables or a k:v mapping of awaitables.
|
|
92
|
+
- Can be used as an async iterator which yields the result values using :class:`ASyncIterator`.
|
|
93
|
+
- Provides progress reporting using :mod:`tqdm` if 'tqdm' is set to True.
|
|
94
|
+
|
|
95
|
+
Note:
|
|
96
|
+
The `return_exceptions` parameter is used to wrap awaitables with exceptions if set to True, allowing exceptions to be returned as results instead of being raised.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
fs: The awaitables to await concurrently. It can be a list of individual awaitables or a mapping of awaitables.
|
|
100
|
+
timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
|
|
101
|
+
return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
|
|
102
|
+
aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
|
|
103
|
+
tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
|
|
104
|
+
**tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
|
|
105
|
+
|
|
106
|
+
Examples:
|
|
107
|
+
Awaiting individual awaitables:
|
|
108
|
+
|
|
109
|
+
>>> awaitables = [async_function1(), async_function2()]
|
|
110
|
+
>>> for coro in as_completed(awaitables):
|
|
111
|
+
... val = await coro
|
|
112
|
+
... ...
|
|
113
|
+
|
|
114
|
+
>>> async for val in as_completed(awaitables, aiter=True):
|
|
115
|
+
... ...
|
|
116
|
+
|
|
117
|
+
Awaiting mappings of awaitables:
|
|
118
|
+
|
|
119
|
+
>>> mapping = {'key1': async_function1(), 'key2': async_function2()}
|
|
120
|
+
>>> for coro in as_completed(mapping):
|
|
121
|
+
... k, v = await coro
|
|
122
|
+
... ...
|
|
123
|
+
|
|
124
|
+
>>> async for k, v in as_completed(mapping, aiter=True):
|
|
125
|
+
... ...
|
|
126
|
+
|
|
127
|
+
See Also:
|
|
128
|
+
- :func:`asyncio.as_completed`
|
|
129
|
+
- :class:`ASyncIterator`
|
|
130
|
+
"""
|
|
131
|
+
if isinstance(fs, Mapping):
|
|
132
|
+
return as_completed_mapping(
|
|
133
|
+
mapping=fs,
|
|
134
|
+
timeout=timeout or 0,
|
|
135
|
+
return_exceptions=return_exceptions,
|
|
136
|
+
aiter=aiter,
|
|
137
|
+
tqdm=tqdm,
|
|
138
|
+
tqdm_kwargs=tqdm_kwargs,
|
|
139
|
+
)
|
|
140
|
+
if return_exceptions:
|
|
141
|
+
fs = [_exc_wrap(f) for f in fs]
|
|
142
|
+
return (
|
|
143
|
+
ASyncIterator(
|
|
144
|
+
__yield_as_completed(fs, timeout=timeout, tqdm=tqdm, **tqdm_kwargs)
|
|
145
|
+
)
|
|
146
|
+
if aiter
|
|
147
|
+
else (
|
|
148
|
+
_tqdm_as_completed(fs, timeout=timeout, **tqdm_kwargs)
|
|
149
|
+
if tqdm
|
|
150
|
+
else _as_completed(fs, timeout=timeout)
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
cdef object as_completed_mapping(
|
|
156
|
+
object mapping,
|
|
157
|
+
unsigned int timeout,
|
|
158
|
+
bint return_exceptions,
|
|
159
|
+
bint aiter,
|
|
160
|
+
bint tqdm,
|
|
161
|
+
dict[str, object] tqdm_kwargs,
|
|
162
|
+
):
|
|
163
|
+
"""
|
|
164
|
+
Concurrently awaits a mapping of awaitable objects and returns an iterator or async iterator of results.
|
|
165
|
+
|
|
166
|
+
This function is designed to await a mapping of awaitable objects, where each key-value pair represents a unique awaitable. It enables concurrent execution and gathers results into an iterator or an async iterator.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
mapping: A dictionary-like object where keys are of type K and values are awaitable objects of type V.
|
|
170
|
+
timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
|
|
171
|
+
return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
|
|
172
|
+
aiter: If True, returns an async iterator of results using :class:`ASyncIterator`. Defaults to False.
|
|
173
|
+
tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
|
|
174
|
+
**tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
|
|
175
|
+
|
|
176
|
+
Example:
|
|
177
|
+
>>> mapping = {'key1': async_function1(), 'key2': async_function2()}
|
|
178
|
+
>>> for coro in as_completed_mapping(mapping):
|
|
179
|
+
... k, v = await coro
|
|
180
|
+
... ...
|
|
181
|
+
|
|
182
|
+
>>> async for k, v in as_completed_mapping(mapping, aiter=True):
|
|
183
|
+
... ...
|
|
184
|
+
|
|
185
|
+
See Also:
|
|
186
|
+
- :func:`as_completed`
|
|
187
|
+
- :class:`ASyncIterator`
|
|
188
|
+
"""
|
|
189
|
+
return as_completed(
|
|
190
|
+
[
|
|
191
|
+
__mapping_wrap(k, v, return_exceptions=return_exceptions)
|
|
192
|
+
for k, v in mapping.items()
|
|
193
|
+
],
|
|
194
|
+
timeout=timeout or None,
|
|
195
|
+
aiter=aiter,
|
|
196
|
+
tqdm=tqdm,
|
|
197
|
+
**tqdm_kwargs
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
async def _exc_wrap(awaitable: Awaitable[T]) -> Union[T, Exception]:
|
|
202
|
+
"""Wraps an awaitable to catch exceptions and return them instead of raising.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
awaitable: The awaitable to wrap.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
The result of the awaitable or the exception if one is raised.
|
|
209
|
+
"""
|
|
210
|
+
try:
|
|
211
|
+
return await awaitable
|
|
212
|
+
except Exception as e:
|
|
213
|
+
return e
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
async def __yield_as_completed(
|
|
217
|
+
futs: Iterable[Awaitable[T]],
|
|
218
|
+
*,
|
|
219
|
+
timeout: Optional[float] = None,
|
|
220
|
+
return_exceptions: bool = False,
|
|
221
|
+
tqdm: bool = False,
|
|
222
|
+
**tqdm_kwargs: Any
|
|
223
|
+
) -> AsyncIterator[T]:
|
|
224
|
+
"""Yields results from awaitables as they complete.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
futs: The awaitables to await.
|
|
228
|
+
timeout: The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
|
|
229
|
+
return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
|
|
230
|
+
tqdm: If True, enables progress reporting using :mod:`tqdm`. Defaults to False.
|
|
231
|
+
**tqdm_kwargs: Additional keyword arguments for :mod:`tqdm` if progress reporting is enabled.
|
|
232
|
+
"""
|
|
233
|
+
for fut in as_completed(
|
|
234
|
+
futs,
|
|
235
|
+
timeout=timeout,
|
|
236
|
+
return_exceptions=return_exceptions,
|
|
237
|
+
tqdm=tqdm,
|
|
238
|
+
**tqdm_kwargs
|
|
239
|
+
):
|
|
240
|
+
yield await fut
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@overload
|
|
244
|
+
async def __mapping_wrap(
|
|
245
|
+
k: K, v: Awaitable[V], return_exceptions: Literal[True] = True
|
|
246
|
+
) -> Union[V, Exception]: ...
|
|
247
|
+
@overload
|
|
248
|
+
async def __mapping_wrap(
|
|
249
|
+
k: K, v: Awaitable[V], return_exceptions: Literal[False] = False
|
|
250
|
+
) -> V: ...
|
|
251
|
+
async def __mapping_wrap(
|
|
252
|
+
k: K, v: Awaitable[V], return_exceptions: bool = False
|
|
253
|
+
) -> Union[V, Exception]:
|
|
254
|
+
"""Wraps a key-value pair of awaitable to catch exceptions and return them with the key.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
k: The key associated with the awaitable.
|
|
258
|
+
v: The awaitable to wrap.
|
|
259
|
+
return_exceptions: If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
A tuple of the key and the result of the awaitable or the exception if one is raised.
|
|
263
|
+
"""
|
|
264
|
+
try:
|
|
265
|
+
return k, await v
|
|
266
|
+
except Exception as e:
|
|
267
|
+
if return_exceptions:
|
|
268
|
+
return k, e
|
|
269
|
+
raise
|