samples-python icon indicating copy to clipboard operation
samples-python copied to clipboard

[Bug] Using < 3.10 on samples using global asyncio.Event fails

Open cretz opened this issue 3 years ago • 0 comments

Describe the bug

asyncio.Event didn't get rid of its loop parameter (and defer loop lookup until use) until >= 3.10. So samples that instantiate an asyncio.Event() globally will get this when running in < 3.10:

Traceback (most recent call last):
  File "scratch\scratch.py", line 106, in <module>
    loop.run_until_complete(main())
  File "asyncio\base_events.py", line 616, in run_until_complete
  File "scratch\scratch.py", line 99, in main
    await interrupt_event.wait()
  File "asyncio\locks.py", line 309, in wait
RuntimeError: Task <Task pending name='Task-1' coro=<main() running at scratch\scratch.py:99> cb=[_run_until_complete_cb() at asyncio\base_events.py:184]> got Future <Future pending> attached to a different loop

Of course delaying creation of the event until after loop creation and passing in the now-removed loop kwarg in the event constructor fixes it.

We just need to find a better way to marry asyncio and signals across our samples.

cretz avatar Dec 14 '22 17:12 cretz