Skip to content

Documentation for autoawait gives example that doesn't work #14865

@brianm78

Description

@brianm78

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions