File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ async def check(lock: AsyncLock):
1717
1818async 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
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments