Skip to content

Commit

Permalink
Don't allow hijacking loop
Browse files Browse the repository at this point in the history
  • Loading branch information
aiudirog committed Oct 17, 2023
1 parent 73d7c01 commit 51221fd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions aiuti/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,16 @@ async def _wrapper(*args: Any, **kwargs: Any) -> Any:
else:
waiting = True # Need to wait for other loop

if waiting: # Wait for other loop, maybe across threads
try:
await ensure_aw(event.wait(), loop)
except RuntimeError: # Target loop most likely closed
pass
if waiting: # Wait for other task, maybe across threads
if aio.get_running_loop() is loop:
await event.wait()
else:
try:
await aio.wrap_future(
aio.run_coroutine_threadsafe(event.wait(), loop),
)
except RuntimeError: # Target loop most likely closed
pass
continue

# First to arrive, cache the value
Expand Down

0 comments on commit 51221fd

Please sign in to comment.