Skip to content

Commit d2ee739

Browse files
committed
Better understanding of where this went wrong internally
1 parent 81e90f4 commit d2ee739

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

_misc/_l.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ async def check(lock: AsyncLock):
1717

1818
async def amain():
1919
lock = AsyncLock()
20-
with threaded_loop() as tl1, threaded_loop() as tl2:
20+
with (
21+
threaded_loop(use_eager_task_factory=False) as tl1,
22+
threaded_loop(use_eager_task_factory=False) as tl2,
23+
):
2124
tsks = {loop.run(check(lock)) for loop in (tl1, tl2) for _ in range(10)}
2225
await asyncio.gather(*tsks)
2326

src/async_utils/_simple_lock.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ def __locked(self) -> bool:
4141
return self._lockv or (any(not w.cancelled() for w in (self._waiters)))
4242

4343
async def __aenter__(self) -> None:
44-
await asyncio.sleep(0) # This yield is non-optional.
44+
# placing the body of acquire here
45+
# causes problems with eager tasks factories.
46+
await self.__acquire()
4547

48+
async def __acquire(self) -> None:
4649
with self._internal_lock:
4750
if not self.__locked():
4851
self._lockv = True
@@ -80,7 +83,6 @@ def _maybe_wake(self) -> None:
8083
break
8184

8285
async def __aexit__(self, *dont_care: object) -> t.Literal[False]:
83-
await asyncio.sleep(0) # this yield is not optional
8486
with self._internal_lock:
8587
self._lockv = False
8688
self._maybe_wake()

0 commit comments

Comments
 (0)