Skip to content

Commit 21aa364

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

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

_misc/_l.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 threaded_loop(use_eager_task_factory=False) as tl1, threaded_loop(use_eager_task_factory=False) as tl2:
2121
tsks = {loop.run(check(lock)) for loop in (tl1, tl2) for _ in range(10)}
2222
await asyncio.gather(*tsks)
2323

src/async_utils/_simple_lock.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +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()
47+
48+
async def __acquire(self) -> None:
4549

4650
with self._internal_lock:
4751
if not self.__locked():
@@ -80,7 +84,6 @@ def _maybe_wake(self) -> None:
8084
break
8185

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

0 commit comments

Comments
 (0)