ipython / ipython/ipython

Documentation for autoawait gives example that doesn't work

Open
#14,865 2 comments 3 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.