xoscar 0.9.0__cp312-cp312-macosx_10_13_x86_64.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.
- xoscar/__init__.py +61 -0
- xoscar/_utils.cpython-312-darwin.so +0 -0
- xoscar/_utils.pxd +36 -0
- xoscar/_utils.pyx +246 -0
- xoscar/_version.py +693 -0
- xoscar/aio/__init__.py +16 -0
- xoscar/aio/base.py +86 -0
- xoscar/aio/file.py +59 -0
- xoscar/aio/lru.py +228 -0
- xoscar/aio/parallelism.py +39 -0
- xoscar/api.py +527 -0
- xoscar/backend.py +67 -0
- xoscar/backends/__init__.py +14 -0
- xoscar/backends/allocate_strategy.py +160 -0
- xoscar/backends/communication/__init__.py +30 -0
- xoscar/backends/communication/base.py +315 -0
- xoscar/backends/communication/core.py +69 -0
- xoscar/backends/communication/dummy.py +253 -0
- xoscar/backends/communication/errors.py +20 -0
- xoscar/backends/communication/socket.py +444 -0
- xoscar/backends/communication/ucx.py +538 -0
- xoscar/backends/communication/utils.py +97 -0
- xoscar/backends/config.py +157 -0
- xoscar/backends/context.py +437 -0
- xoscar/backends/core.py +352 -0
- xoscar/backends/indigen/__init__.py +16 -0
- xoscar/backends/indigen/__main__.py +19 -0
- xoscar/backends/indigen/backend.py +51 -0
- xoscar/backends/indigen/driver.py +26 -0
- xoscar/backends/indigen/fate_sharing.py +221 -0
- xoscar/backends/indigen/pool.py +515 -0
- xoscar/backends/indigen/shared_memory.py +548 -0
- xoscar/backends/message.cpython-312-darwin.so +0 -0
- xoscar/backends/message.pyi +255 -0
- xoscar/backends/message.pyx +646 -0
- xoscar/backends/pool.py +1630 -0
- xoscar/backends/router.py +285 -0
- xoscar/backends/test/__init__.py +16 -0
- xoscar/backends/test/backend.py +38 -0
- xoscar/backends/test/pool.py +233 -0
- xoscar/batch.py +256 -0
- xoscar/collective/__init__.py +27 -0
- xoscar/collective/backend/__init__.py +13 -0
- xoscar/collective/backend/nccl_backend.py +160 -0
- xoscar/collective/common.py +102 -0
- xoscar/collective/core.py +737 -0
- xoscar/collective/process_group.py +687 -0
- xoscar/collective/utils.py +41 -0
- xoscar/collective/xoscar_pygloo.cpython-312-darwin.so +0 -0
- xoscar/collective/xoscar_pygloo.pyi +239 -0
- xoscar/constants.py +23 -0
- xoscar/context.cpython-312-darwin.so +0 -0
- xoscar/context.pxd +21 -0
- xoscar/context.pyx +368 -0
- xoscar/core.cpython-312-darwin.so +0 -0
- xoscar/core.pxd +51 -0
- xoscar/core.pyx +664 -0
- xoscar/debug.py +188 -0
- xoscar/driver.py +42 -0
- xoscar/errors.py +63 -0
- xoscar/libcpp.pxd +31 -0
- xoscar/metrics/__init__.py +21 -0
- xoscar/metrics/api.py +288 -0
- xoscar/metrics/backends/__init__.py +13 -0
- xoscar/metrics/backends/console/__init__.py +13 -0
- xoscar/metrics/backends/console/console_metric.py +82 -0
- xoscar/metrics/backends/metric.py +149 -0
- xoscar/metrics/backends/prometheus/__init__.py +13 -0
- xoscar/metrics/backends/prometheus/prometheus_metric.py +70 -0
- xoscar/nvutils.py +717 -0
- xoscar/profiling.py +260 -0
- xoscar/serialization/__init__.py +20 -0
- xoscar/serialization/aio.py +141 -0
- xoscar/serialization/core.cpython-312-darwin.so +0 -0
- xoscar/serialization/core.pxd +28 -0
- xoscar/serialization/core.pyi +57 -0
- xoscar/serialization/core.pyx +944 -0
- xoscar/serialization/cuda.py +111 -0
- xoscar/serialization/exception.py +48 -0
- xoscar/serialization/mlx.py +67 -0
- xoscar/serialization/numpy.py +82 -0
- xoscar/serialization/pyfury.py +37 -0
- xoscar/serialization/scipy.py +72 -0
- xoscar/serialization/torch.py +180 -0
- xoscar/utils.py +522 -0
- xoscar/virtualenv/__init__.py +34 -0
- xoscar/virtualenv/core.py +268 -0
- xoscar/virtualenv/platform.py +56 -0
- xoscar/virtualenv/utils.py +100 -0
- xoscar/virtualenv/uv.py +321 -0
- xoscar-0.9.0.dist-info/METADATA +230 -0
- xoscar-0.9.0.dist-info/RECORD +94 -0
- xoscar-0.9.0.dist-info/WHEEL +6 -0
- xoscar-0.9.0.dist-info/top_level.txt +2 -0
xoscar/aio/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
from .file import AioFileObject
|
|
15
|
+
from .lru import alru_cache
|
|
16
|
+
from .parallelism import AioEvent
|
xoscar/aio/base.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import asyncio
|
|
18
|
+
import functools
|
|
19
|
+
from concurrent.futures import Executor
|
|
20
|
+
from typing import Any, Type
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _make_delegate_method(attr):
|
|
24
|
+
async def method(self, *args, **kwargs):
|
|
25
|
+
func = functools.partial(getattr(self._file, attr), *args, **kwargs)
|
|
26
|
+
return await self._loop.run_in_executor(self._executor, func)
|
|
27
|
+
|
|
28
|
+
return method
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _make_proxy_method(attr):
|
|
32
|
+
def method(self, *args, **kwargs):
|
|
33
|
+
return getattr(self._file, attr)(*args, **kwargs)
|
|
34
|
+
|
|
35
|
+
return method
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _make_proxy_property(attr):
|
|
39
|
+
def proxy_property(self):
|
|
40
|
+
return getattr(self._file, attr)
|
|
41
|
+
|
|
42
|
+
return property(proxy_property)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def delegate_to_executor(*attrs):
|
|
46
|
+
def wrap_cls(cls: Type):
|
|
47
|
+
for attr in attrs:
|
|
48
|
+
setattr(cls, attr, _make_delegate_method(attr))
|
|
49
|
+
return cls
|
|
50
|
+
|
|
51
|
+
return wrap_cls
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def proxy_method_directly(*attrs):
|
|
55
|
+
def wrap_cls(cls: Type):
|
|
56
|
+
for attr in attrs:
|
|
57
|
+
setattr(cls, attr, _make_proxy_method(attr))
|
|
58
|
+
return cls
|
|
59
|
+
|
|
60
|
+
return wrap_cls
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def proxy_property_directly(*attrs):
|
|
64
|
+
def wrap_cls(cls):
|
|
65
|
+
for attr in attrs:
|
|
66
|
+
setattr(cls, attr, _make_proxy_property(attr))
|
|
67
|
+
return cls
|
|
68
|
+
|
|
69
|
+
return wrap_cls
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class AioBase:
|
|
73
|
+
def __init__(
|
|
74
|
+
self,
|
|
75
|
+
file: Any,
|
|
76
|
+
loop: asyncio.BaseEventLoop | None = None,
|
|
77
|
+
executor: Executor | None = None,
|
|
78
|
+
):
|
|
79
|
+
if loop is None:
|
|
80
|
+
loop = asyncio.get_event_loop() # type: ignore
|
|
81
|
+
if isinstance(file, AioBase):
|
|
82
|
+
file = file._file # type: ignore
|
|
83
|
+
|
|
84
|
+
self._file = file
|
|
85
|
+
self._loop = loop
|
|
86
|
+
self._executor = executor
|
xoscar/aio/file.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .base import (
|
|
16
|
+
AioBase,
|
|
17
|
+
delegate_to_executor,
|
|
18
|
+
proxy_method_directly,
|
|
19
|
+
proxy_property_directly,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@delegate_to_executor(
|
|
24
|
+
"close",
|
|
25
|
+
"flush",
|
|
26
|
+
"isatty",
|
|
27
|
+
"read",
|
|
28
|
+
"read1",
|
|
29
|
+
"readinto",
|
|
30
|
+
"readline",
|
|
31
|
+
"readlines",
|
|
32
|
+
"seek",
|
|
33
|
+
"seekable",
|
|
34
|
+
"tell",
|
|
35
|
+
"truncate",
|
|
36
|
+
"writable",
|
|
37
|
+
"write",
|
|
38
|
+
"writelines",
|
|
39
|
+
)
|
|
40
|
+
@proxy_method_directly("fileno", "readable")
|
|
41
|
+
@proxy_property_directly("closed", "name", "mode")
|
|
42
|
+
class AioFileObject(AioBase):
|
|
43
|
+
def __aiter__(self):
|
|
44
|
+
return self
|
|
45
|
+
|
|
46
|
+
async def __anext__(self):
|
|
47
|
+
"""Simulate normal file iteration."""
|
|
48
|
+
line = await self.readline()
|
|
49
|
+
if line:
|
|
50
|
+
return line
|
|
51
|
+
else:
|
|
52
|
+
raise StopAsyncIteration
|
|
53
|
+
|
|
54
|
+
async def __aenter__(self):
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
58
|
+
await self.close()
|
|
59
|
+
self._file = None
|
xoscar/aio/lru.py
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# The MIT License
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2018 aio-libs team https://github.com/aio-libs/
|
|
4
|
+
# Copyright (c) 2017 Ocean S. A. https://ocean.io/
|
|
5
|
+
# Copyright (c) 2016-2017 WikiBusiness Corporation http://wikibusiness.org/
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
|
|
25
|
+
import asyncio
|
|
26
|
+
import os
|
|
27
|
+
import weakref
|
|
28
|
+
from collections import OrderedDict
|
|
29
|
+
from functools import _CacheInfo, _make_key, partial, wraps
|
|
30
|
+
|
|
31
|
+
__version__ = "1.0.2"
|
|
32
|
+
|
|
33
|
+
__all__ = ("alru_cache", "clear_all_alru_caches")
|
|
34
|
+
|
|
35
|
+
_is_ci = (os.environ.get("CI") or "0").lower() in ("1", "true")
|
|
36
|
+
_all_wrapped: weakref.WeakSet = weakref.WeakSet()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def clear_all_alru_caches():
|
|
40
|
+
for wrapped in _all_wrapped:
|
|
41
|
+
wrapped.cache_clear()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def unpartial(fn):
|
|
45
|
+
while hasattr(fn, "func"):
|
|
46
|
+
fn = fn.func
|
|
47
|
+
|
|
48
|
+
return fn
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _done_callback(fut, task):
|
|
52
|
+
if task.cancelled():
|
|
53
|
+
fut.cancel()
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
exc = task.exception()
|
|
57
|
+
if exc is not None:
|
|
58
|
+
fut.set_exception(exc)
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
fut.set_result(task.result())
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _cache_invalidate(wrapped, typed, *args, **kwargs):
|
|
65
|
+
key = _make_key(args, kwargs, typed)
|
|
66
|
+
|
|
67
|
+
exists = key in wrapped._cache
|
|
68
|
+
|
|
69
|
+
if exists:
|
|
70
|
+
wrapped._cache.pop(key)
|
|
71
|
+
|
|
72
|
+
return exists
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _cache_clear(wrapped):
|
|
76
|
+
wrapped.hits = wrapped.misses = 0
|
|
77
|
+
wrapped._cache = OrderedDict()
|
|
78
|
+
wrapped.tasks = set()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _open(wrapped):
|
|
82
|
+
if not wrapped.closed:
|
|
83
|
+
raise RuntimeError("alru_cache is not closed")
|
|
84
|
+
|
|
85
|
+
was_closed = (
|
|
86
|
+
wrapped.hits == wrapped.misses == len(wrapped.tasks) == len(wrapped._cache) == 0
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if not was_closed:
|
|
90
|
+
raise RuntimeError("alru_cache was not closed correctly")
|
|
91
|
+
|
|
92
|
+
wrapped.closed = False
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _close(wrapped, *, cancel=False, return_exceptions=True):
|
|
96
|
+
if wrapped.closed:
|
|
97
|
+
raise RuntimeError("alru_cache is closed")
|
|
98
|
+
|
|
99
|
+
wrapped.closed = True
|
|
100
|
+
|
|
101
|
+
if cancel:
|
|
102
|
+
for task in wrapped.tasks:
|
|
103
|
+
if not task.done(): # not sure is it possible
|
|
104
|
+
task.cancel()
|
|
105
|
+
|
|
106
|
+
return _wait_closed(wrapped, return_exceptions=return_exceptions)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def _wait_closed(wrapped, *, return_exceptions):
|
|
110
|
+
wait_closed = asyncio.gather(*wrapped.tasks, return_exceptions=return_exceptions)
|
|
111
|
+
|
|
112
|
+
wait_closed.add_done_callback(partial(_close_waited, wrapped))
|
|
113
|
+
|
|
114
|
+
ret = await wait_closed
|
|
115
|
+
|
|
116
|
+
# hack to get _close_waited callback to be executed
|
|
117
|
+
await asyncio.sleep(0)
|
|
118
|
+
|
|
119
|
+
return ret
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _close_waited(wrapped, _):
|
|
123
|
+
wrapped.cache_clear()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _cache_info(wrapped, maxsize):
|
|
127
|
+
return _CacheInfo(
|
|
128
|
+
wrapped.hits,
|
|
129
|
+
wrapped.misses,
|
|
130
|
+
maxsize,
|
|
131
|
+
len(wrapped._cache),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def __cache_touch(wrapped, key):
|
|
136
|
+
try:
|
|
137
|
+
wrapped._cache.move_to_end(key)
|
|
138
|
+
except KeyError: # not sure is it possible
|
|
139
|
+
pass
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _cache_hit(wrapped, key):
|
|
143
|
+
wrapped.hits += 1
|
|
144
|
+
__cache_touch(wrapped, key)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _cache_miss(wrapped, key):
|
|
148
|
+
wrapped.misses += 1
|
|
149
|
+
__cache_touch(wrapped, key)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def alru_cache(
|
|
153
|
+
fn=None,
|
|
154
|
+
maxsize=128,
|
|
155
|
+
typed=False,
|
|
156
|
+
*,
|
|
157
|
+
cache_exceptions=True,
|
|
158
|
+
):
|
|
159
|
+
def wrapper(fn):
|
|
160
|
+
_origin = unpartial(fn)
|
|
161
|
+
|
|
162
|
+
if not asyncio.iscoroutinefunction(_origin):
|
|
163
|
+
raise RuntimeError("Coroutine function is required, got {}".format(fn))
|
|
164
|
+
|
|
165
|
+
# functools.partialmethod support
|
|
166
|
+
if hasattr(fn, "_make_unbound_method"):
|
|
167
|
+
fn = fn._make_unbound_method()
|
|
168
|
+
|
|
169
|
+
@wraps(fn)
|
|
170
|
+
async def wrapped(*fn_args, **fn_kwargs):
|
|
171
|
+
if wrapped.closed:
|
|
172
|
+
raise RuntimeError("alru_cache is closed for {}".format(wrapped))
|
|
173
|
+
|
|
174
|
+
loop = asyncio.get_event_loop()
|
|
175
|
+
|
|
176
|
+
key = _make_key(fn_args, fn_kwargs, typed)
|
|
177
|
+
|
|
178
|
+
fut = wrapped._cache.get(key)
|
|
179
|
+
|
|
180
|
+
if fut is not None:
|
|
181
|
+
if not fut.done():
|
|
182
|
+
_cache_hit(wrapped, key)
|
|
183
|
+
return await asyncio.shield(fut)
|
|
184
|
+
|
|
185
|
+
exc = fut._exception
|
|
186
|
+
|
|
187
|
+
if exc is None or cache_exceptions:
|
|
188
|
+
_cache_hit(wrapped, key)
|
|
189
|
+
return fut.result()
|
|
190
|
+
|
|
191
|
+
# exception here and cache_exceptions == False
|
|
192
|
+
wrapped._cache.pop(key)
|
|
193
|
+
|
|
194
|
+
fut = loop.create_future()
|
|
195
|
+
task = loop.create_task(fn(*fn_args, **fn_kwargs))
|
|
196
|
+
task.add_done_callback(partial(_done_callback, fut))
|
|
197
|
+
|
|
198
|
+
wrapped.tasks.add(task)
|
|
199
|
+
task.add_done_callback(wrapped.tasks.remove)
|
|
200
|
+
|
|
201
|
+
wrapped._cache[key] = fut
|
|
202
|
+
|
|
203
|
+
if maxsize is not None and len(wrapped._cache) > maxsize:
|
|
204
|
+
wrapped._cache.popitem(last=False)
|
|
205
|
+
|
|
206
|
+
_cache_miss(wrapped, key)
|
|
207
|
+
return await asyncio.shield(fut)
|
|
208
|
+
|
|
209
|
+
_cache_clear(wrapped)
|
|
210
|
+
wrapped._origin = _origin
|
|
211
|
+
wrapped.closed = False
|
|
212
|
+
wrapped.cache_info = partial(_cache_info, wrapped, maxsize)
|
|
213
|
+
wrapped.cache_clear = partial(_cache_clear, wrapped)
|
|
214
|
+
wrapped.invalidate = partial(_cache_invalidate, wrapped, typed)
|
|
215
|
+
wrapped.close = partial(_close, wrapped)
|
|
216
|
+
wrapped.open = partial(_open, wrapped)
|
|
217
|
+
|
|
218
|
+
if _is_ci:
|
|
219
|
+
_all_wrapped.add(wrapped)
|
|
220
|
+
return wrapped
|
|
221
|
+
|
|
222
|
+
if fn is None:
|
|
223
|
+
return wrapper
|
|
224
|
+
|
|
225
|
+
if callable(fn) or hasattr(fn, "_make_unbound_method"):
|
|
226
|
+
return wrapper(fn)
|
|
227
|
+
|
|
228
|
+
raise NotImplementedError("{} decorating is not supported".format(fn))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright 2022-2023 XProbe Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import asyncio
|
|
18
|
+
import multiprocessing
|
|
19
|
+
import threading
|
|
20
|
+
from concurrent.futures import Executor
|
|
21
|
+
from typing import Union
|
|
22
|
+
|
|
23
|
+
from .base import AioBase, delegate_to_executor, proxy_method_directly
|
|
24
|
+
|
|
25
|
+
event_types = Union[threading.Event, multiprocessing.Event] # type: ignore
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@delegate_to_executor("wait")
|
|
29
|
+
@proxy_method_directly("set", "is_set", "clear")
|
|
30
|
+
class AioEvent(AioBase):
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
event: event_types | None = None,
|
|
34
|
+
loop: asyncio.BaseEventLoop | None = None,
|
|
35
|
+
executor: Executor | None = None,
|
|
36
|
+
):
|
|
37
|
+
if event is None:
|
|
38
|
+
event = threading.Event()
|
|
39
|
+
super().__init__(event, loop=loop, executor=executor)
|