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):
17
17
18
18
async def amain ():
19
19
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
+ ):
21
24
tsks = {loop .run (check (lock )) for loop in (tl1 , tl2 ) for _ in range (10 )}
22
25
await asyncio .gather (* tsks )
23
26
Original file line number Diff line number Diff line change @@ -41,8 +41,11 @@ def __locked(self) -> bool:
41
41
return self ._lockv or (any (not w .cancelled () for w in (self ._waiters )))
42
42
43
43
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 ()
45
47
48
+ async def __acquire (self ) -> None :
46
49
with self ._internal_lock :
47
50
if not self .__locked ():
48
51
self ._lockv = True
@@ -80,7 +83,6 @@ def _maybe_wake(self) -> None:
80
83
break
81
84
82
85
async def __aexit__ (self , * dont_care : object ) -> t .Literal [False ]:
83
- await asyncio .sleep (0 ) # this yield is not optional
84
86
with self ._internal_lock :
85
87
self ._lockv = False
86
88
self ._maybe_wake ()
You can’t perform that action at this time.
0 commit comments