ez-a-sync 0.32.11__cp312-cp312-musllinux_1_2_i686.whl → 0.32.13__cp312-cp312-musllinux_1_2_i686.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/_smart.c +1122 -1133
- a_sync/_smart.cpython-312-i386-linux-musl.so +0 -0
- a_sync/_smart.pyx +11 -10
- a_sync/asyncio/create_task.c +735 -579
- a_sync/asyncio/create_task.cpython-312-i386-linux-musl.so +0 -0
- a_sync/asyncio/create_task.pyx +7 -4
- a_sync/debugging.c +3 -2
- a_sync/debugging.cpython-312-i386-linux-musl.so +0 -0
- a_sync/iter.c +216 -81
- a_sync/iter.cpython-312-i386-linux-musl.so +0 -0
- a_sync/iter.pxd +2 -0
- a_sync/primitives/locks/event.c +426 -428
- a_sync/primitives/locks/event.cpython-312-i386-linux-musl.so +0 -0
- a_sync/primitives/locks/event.pyx +3 -1
- a_sync/primitives/locks/prio_semaphore.c +2623 -1503
- a_sync/primitives/locks/prio_semaphore.cpython-312-i386-linux-musl.so +0 -0
- a_sync/primitives/locks/prio_semaphore.pxd +9 -8
- a_sync/primitives/locks/prio_semaphore.pyx +65 -22
- a_sync/primitives/locks/semaphore.c +1048 -1051
- a_sync/primitives/locks/semaphore.cpython-312-i386-linux-musl.so +0 -0
- a_sync/primitives/locks/semaphore.pyx +4 -2
- a_sync/task.py +22 -6
- {ez_a_sync-0.32.11.dist-info → ez_a_sync-0.32.13.dist-info}/METADATA +1 -1
- {ez_a_sync-0.32.11.dist-info → ez_a_sync-0.32.13.dist-info}/RECORD +27 -27
- {ez_a_sync-0.32.11.dist-info → ez_a_sync-0.32.13.dist-info}/WHEEL +1 -1
- {ez_a_sync-0.32.11.dist-info → ez_a_sync-0.32.13.dist-info}/licenses/LICENSE.txt +0 -0
- {ez_a_sync-0.32.11.dist-info → ez_a_sync-0.32.13.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from a_sync.primitives.locks.semaphore cimport Semaphore
|
|
2
2
|
|
|
3
3
|
cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
4
|
-
cdef dict[object, _AbstractPrioritySemaphoreContextManager] _context_managers
|
|
5
|
-
cdef Py_ssize_t _capacity
|
|
6
|
-
cdef
|
|
7
|
-
cdef object _top_priority
|
|
8
|
-
cdef
|
|
4
|
+
cdef readonly dict[object, _AbstractPrioritySemaphoreContextManager] _context_managers
|
|
5
|
+
cdef readonly Py_ssize_t _capacity
|
|
6
|
+
cdef readonly set _potential_lost_waiters
|
|
7
|
+
cdef readonly object _top_priority
|
|
8
|
+
cdef readonly _AbstractPrioritySemaphoreContextManager _top_priority_manager
|
|
9
|
+
cdef readonly object _context_manager_class
|
|
9
10
|
cpdef object acquire(self)
|
|
10
11
|
cdef _AbstractPrioritySemaphoreContextManager c_getitem(self, object priority)
|
|
11
12
|
cdef dict[object, int] _count_waiters(self)
|
|
@@ -15,9 +16,9 @@ cdef class PrioritySemaphore(_AbstractPrioritySemaphore):
|
|
|
15
16
|
pass
|
|
16
17
|
|
|
17
18
|
cdef class _AbstractPrioritySemaphoreContextManager(Semaphore):
|
|
18
|
-
cdef _AbstractPrioritySemaphore _parent
|
|
19
|
-
cdef object _priority
|
|
20
|
-
cdef str _priority_name
|
|
19
|
+
cdef readonly _AbstractPrioritySemaphore _parent
|
|
20
|
+
cdef readonly object _priority
|
|
21
|
+
cdef readonly str _priority_name
|
|
21
22
|
cpdef str _repr_no_parent_(self)
|
|
22
23
|
|
|
23
24
|
cdef class _PrioritySemaphoreContextManager(_AbstractPrioritySemaphoreContextManager):
|
|
@@ -11,11 +11,10 @@ import heapq
|
|
|
11
11
|
from logging import getLogger
|
|
12
12
|
from typing import List, Literal, Optional, Protocol, Set, Type, TypeVar
|
|
13
13
|
|
|
14
|
+
from cpython.unicode cimport PyUnicode_CompareWithASCIIString
|
|
15
|
+
|
|
14
16
|
from a_sync.primitives.locks.semaphore cimport Semaphore
|
|
15
17
|
|
|
16
|
-
# cdef asyncio
|
|
17
|
-
cdef object Future = asyncio.Future
|
|
18
|
-
del asyncio
|
|
19
18
|
|
|
20
19
|
# cdef collections
|
|
21
20
|
cdef object deque = collections.deque
|
|
@@ -65,7 +64,7 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
65
64
|
"""A heap queue of context managers, sorted by priority."""
|
|
66
65
|
|
|
67
66
|
# NOTE: This should (hopefully) be temporary
|
|
68
|
-
self._potential_lost_waiters
|
|
67
|
+
self._potential_lost_waiters = set()
|
|
69
68
|
"""A list of futures representing waiters that might have been lost."""
|
|
70
69
|
|
|
71
70
|
def __init__(
|
|
@@ -92,6 +91,9 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
92
91
|
"""The initial capacity of the semaphore."""
|
|
93
92
|
|
|
94
93
|
self._top_priority = top_priority
|
|
94
|
+
self._top_priority_manager = context_manager_class(
|
|
95
|
+
self, top_priority, name=self.name
|
|
96
|
+
)
|
|
95
97
|
self._context_manager_class = context_manager_class
|
|
96
98
|
|
|
97
99
|
def __repr__(self) -> str:
|
|
@@ -108,7 +110,7 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
108
110
|
>>> async with semaphore:
|
|
109
111
|
... await do_stuff()
|
|
110
112
|
"""
|
|
111
|
-
await self.
|
|
113
|
+
await self._top_priority_manager.acquire()
|
|
112
114
|
|
|
113
115
|
async def __aexit__(self, *_) -> None:
|
|
114
116
|
"""Exits the semaphore context, releasing it with the top priority.
|
|
@@ -120,7 +122,7 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
120
122
|
>>> async with semaphore:
|
|
121
123
|
... await do_stuff()
|
|
122
124
|
"""
|
|
123
|
-
self.
|
|
125
|
+
self._top_priority_manager.release()
|
|
124
126
|
|
|
125
127
|
cpdef object acquire(self):
|
|
126
128
|
"""Acquires the semaphore with the top priority.
|
|
@@ -131,7 +133,7 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
131
133
|
>>> semaphore = _AbstractPrioritySemaphore(5)
|
|
132
134
|
>>> await semaphore.acquire()
|
|
133
135
|
"""
|
|
134
|
-
return self.
|
|
136
|
+
return self._top_priority_manager.acquire()
|
|
135
137
|
|
|
136
138
|
def __getitem__(
|
|
137
139
|
self, priority: Optional[PT]
|
|
@@ -154,8 +156,10 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
154
156
|
cdef _AbstractPrioritySemaphoreContextManager context_manager
|
|
155
157
|
cdef dict[object, _AbstractPrioritySemaphoreContextManager] context_managers
|
|
156
158
|
|
|
159
|
+
if priority is None or priority == self._top_priority:
|
|
160
|
+
return self._top_priority_manager
|
|
161
|
+
|
|
157
162
|
context_managers = self._context_managers
|
|
158
|
-
priority = self._top_priority if priority is None else priority
|
|
159
163
|
context_manager = context_managers.get(priority)
|
|
160
164
|
if context_manager is None:
|
|
161
165
|
context_manager = self._context_manager_class(
|
|
@@ -213,12 +217,36 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
213
217
|
>>> semaphore._wake_up_next()
|
|
214
218
|
"""
|
|
215
219
|
cdef _AbstractPrioritySemaphoreContextManager manager
|
|
220
|
+
cdef object manager_waiters, get_next
|
|
216
221
|
cdef Py_ssize_t start_len, end_len
|
|
217
|
-
cdef
|
|
222
|
+
cdef set potential_lost_waiters
|
|
223
|
+
cdef bint woke_up, debug_logs
|
|
224
|
+
|
|
225
|
+
manager = self._top_priority_manager
|
|
226
|
+
manager_waiters = manager._Semaphore__waiters
|
|
227
|
+
potential_lost_waiters = self._potential_lost_waiters
|
|
228
|
+
debug_logs = _logger_is_enabled(DEBUG)
|
|
229
|
+
if manager_waiters:
|
|
230
|
+
get_next = manager_waiters.popleft
|
|
231
|
+
while manager_waiters:
|
|
232
|
+
waiter = get_next()
|
|
233
|
+
potential_lost_waiters.discard(waiter)
|
|
234
|
+
if _is_not_done(waiter):
|
|
235
|
+
waiter.set_result(None)
|
|
236
|
+
if debug_logs:
|
|
237
|
+
log_debug("woke up %s", (waiter, ))
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
while manager_waiters:
|
|
241
|
+
waiter = get_next()
|
|
242
|
+
potential_lost_waiters.discard(waiter)
|
|
243
|
+
if _is_not_done(waiter):
|
|
244
|
+
waiter.set_result(None)
|
|
245
|
+
if debug_logs:
|
|
246
|
+
log_debug("woke up %s", (waiter, ))
|
|
247
|
+
return
|
|
218
248
|
|
|
219
249
|
cdef list self_waiters = self._Semaphore__waiters
|
|
220
|
-
cdef list potential_lost_waiters = self._potential_lost_waiters
|
|
221
|
-
cdef bint debug_logs = _logger_is_enabled(DEBUG)
|
|
222
250
|
while self_waiters:
|
|
223
251
|
manager = heappop(self_waiters)
|
|
224
252
|
if len(manager) == 0:
|
|
@@ -240,9 +268,10 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
240
268
|
if not manager_waiters:
|
|
241
269
|
log_debug("not manager._Semaphore__waiters", ())
|
|
242
270
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
271
|
+
if manager_waiters:
|
|
272
|
+
get_next = manager_waiters.popleft
|
|
273
|
+
waiter = get_next()
|
|
274
|
+
potential_lost_waiters.discard(waiter)
|
|
246
275
|
if _is_not_done(waiter):
|
|
247
276
|
waiter.set_result(None)
|
|
248
277
|
woke_up = True
|
|
@@ -250,6 +279,17 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
250
279
|
log_debug("woke up %s", (waiter, ))
|
|
251
280
|
break
|
|
252
281
|
|
|
282
|
+
if not woke_up:
|
|
283
|
+
while manager_waiters:
|
|
284
|
+
waiter = get_next()
|
|
285
|
+
potential_lost_waiters.discard(waiter)
|
|
286
|
+
if _is_not_done(waiter):
|
|
287
|
+
waiter.set_result(None)
|
|
288
|
+
woke_up = True
|
|
289
|
+
if debug_logs:
|
|
290
|
+
log_debug("woke up %s", (waiter, ))
|
|
291
|
+
break
|
|
292
|
+
|
|
253
293
|
if not woke_up:
|
|
254
294
|
self._context_managers.pop(manager._priority)
|
|
255
295
|
continue
|
|
@@ -269,14 +309,14 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
|
|
|
269
309
|
# emergency procedure (hopefully temporary):
|
|
270
310
|
if not debug_logs:
|
|
271
311
|
while potential_lost_waiters:
|
|
272
|
-
waiter = potential_lost_waiters.pop(
|
|
312
|
+
waiter = potential_lost_waiters.pop()
|
|
273
313
|
if _is_not_done(waiter):
|
|
274
314
|
waiter.set_result(None)
|
|
275
315
|
return
|
|
276
316
|
return
|
|
277
317
|
|
|
278
318
|
while potential_lost_waiters:
|
|
279
|
-
waiter = potential_lost_waiters.pop(
|
|
319
|
+
waiter = potential_lost_waiters.pop()
|
|
280
320
|
log_debug("we found a lost waiter %s", (waiter, ))
|
|
281
321
|
if _is_not_done(waiter):
|
|
282
322
|
waiter.set_result(None)
|
|
@@ -393,7 +433,7 @@ cdef class _AbstractPrioritySemaphoreContextManager(Semaphore):
|
|
|
393
433
|
self._Semaphore__waiters = deque()
|
|
394
434
|
fut = self._c_get_loop().create_future()
|
|
395
435
|
self._Semaphore__waiters.append(fut)
|
|
396
|
-
parent._potential_lost_waiters.
|
|
436
|
+
parent._potential_lost_waiters.add(fut)
|
|
397
437
|
try:
|
|
398
438
|
await fut
|
|
399
439
|
except:
|
|
@@ -417,11 +457,14 @@ cdef class _AbstractPrioritySemaphoreContextManager(Semaphore):
|
|
|
417
457
|
self._parent.release()
|
|
418
458
|
|
|
419
459
|
|
|
420
|
-
cdef inline bint _is_not_done(fut: Future):
|
|
421
|
-
return
|
|
460
|
+
cdef inline bint _is_not_done(fut: asyncio.Future):
|
|
461
|
+
return PyUnicode_CompareWithASCIIString(fut._state, b"PENDING") == 0
|
|
462
|
+
|
|
463
|
+
cdef inline bint _is_not_cancelled(fut: asyncio.Future):
|
|
464
|
+
return PyUnicode_CompareWithASCIIString(fut._state, b"CANCELLED") != 0
|
|
422
465
|
|
|
423
|
-
|
|
424
|
-
|
|
466
|
+
|
|
467
|
+
del asyncio
|
|
425
468
|
|
|
426
469
|
|
|
427
470
|
cdef class _PrioritySemaphoreContextManager(_AbstractPrioritySemaphoreContextManager):
|
|
@@ -505,7 +548,7 @@ cdef class PrioritySemaphore(_AbstractPrioritySemaphore):
|
|
|
505
548
|
"""A heap queue of context managers, sorted by priority."""
|
|
506
549
|
|
|
507
550
|
# NOTE: This should (hopefully) be temporary
|
|
508
|
-
self._potential_lost_waiters
|
|
551
|
+
self._potential_lost_waiters = set()
|
|
509
552
|
"""A list of futures representing waiters that might have been lost."""
|
|
510
553
|
|
|
511
554
|
def __init__(
|