I have been banging my head against the wall with this for some time now and I am not really sure how to deal with it properly.
I have a simple test.py script
import asyncio
print(f'{asyncio.get_event_loop()}')
print(f'{asyncio.get_event_loop_policy()}')
When I run this in iPython, jupyter qtconsole or jupyter notebook, the output is as follows:
<_WindowsSelectorEventLoop running=True closed=False debug=False>
<asyncio.windows_events.WindowsSelectorEventLoopPolicy object at 0x0000029DE7A96D30>
However, when the very same script is run from the command line (PowerShell) on the same machine with "python test.py", I get:
<ProactorEventLoop running=False closed=False debug=False>
<asyncio.windows_events.WindowsProactorEventLoopPolicy object at 0x000001C666186E20>
Obviously, asyncio does something different to set up the default event loop depending on the context, but I don't understand why and how. Furthermore, the main problem is that the event loop is running in the former case and not running in the latter. This causes runtime errors in scripts that use asyncio functionality, but only if they are run from the command line and not otherwise.
Needless to say, this is baffling and troubling behaviour. I am loath to come up with workarounds for something like this, as it just seems too bizarre. I am using Python 3.9.4 on Windows 11.
Does anybody have ideas of how to best deal with this or have dealt with this in the past?