You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a toy program that sets an asyncio.Event when a signal is received, and runs an asynchronous function (passive_wait) that waits for that signal to be set.
When the following code is executed and a signal is sent externally, it is detected by the program, but the function waiting function does not resume execution.
It does finish correctly if another async function is executed alongside, like when uncommenting the line active_wait(),.
importasyncioimportsignalevent=asyncio.Event()
def_signal_handler(*_) ->None:
event.set()
print("Event triggered")
signal.signal(signal.SIGINT, _signal_handler)
signal.signal(signal.SIGTERM, _signal_handler)
asyncdefpassive_wait():
print("Pre event")
awaitevent.wait()
print("Post event")
asyncdefactive_wait():
whilenotevent.is_set():
awaitasyncio.sleep(1)
asyncdefmain():
awaitasyncio.gather(
passive_wait(),
# Uncommenting the following line makes it stop correctly#active_wait(),
)
asyncio.run(main())
# Send the signal externally
If that's the intended behavior I would love some pointers.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered:
Yes this is intentional behavior. I wonder if python could set a flag when executing from a reentrant context like a signal handler or finalizer so that Event.set could crash in this case
Bug report
Bug description:
This is a toy program that sets an asyncio.Event when a signal is received, and runs an asynchronous function (
passive_wait
) that waits for that signal to be set.When the following code is executed and a signal is sent externally, it is detected by the program, but the function waiting function does not resume execution.
It does finish correctly if another async function is executed alongside, like when uncommenting the line
active_wait(),
.If that's the intended behavior I would love some pointers.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: