The documentation for autoawait (ie. allowing automatic use of an event loop) at https://ipython.readthedocs.io/en/stable/interactive/autoawait.html gives some examples like:
In [1]: import aiohttp
...: session = aiohttp.ClientSession()
...: result = session.get('https://api.github.com')
In [2]: response = await result
However, this doesn't actually work as written - the first block will raise RuntimeError: no running event loop.
I think this is because no event loop is created unless the code being run actually contains an await instruction or similar, so code that requires the event loop to be running, but doesn't itself await will fail.
Eg. modifying the above to include the response = await result in the same block as the setup logic does work.
Ideally there'd be a way to handle code like this - I'm not sure if always running an event loop (possibly configurable) has problems. If not, I think at least the examples should be amended to mention this.
The documentation for autoawait (ie. allowing automatic use of an event loop) at https://ipython.readthedocs.io/en/stable/interactive/autoawait.html gives some examples like:
However, this doesn't actually work as written - the first block will raise
RuntimeError: no running event loop.I think this is because no event loop is created unless the code being run actually contains an
awaitinstruction or similar, so code that requires the event loop to be running, but doesn't itself await will fail.Eg. modifying the above to include the
response = await resultin the same block as the setup logic does work.Ideally there'd be a way to handle code like this - I'm not sure if always running an event loop (possibly configurable) has problems. If not, I think at least the examples should be amended to mention this.