Module: core.async_helpers

Async helper function that are invalid syntax on Python 3.5 and below.

This code is best effort, and may have edge cases not behaving as expected. In particular it contain a number of heuristics to detect whether code is effectively async and need to run in an event loop or not.

Some constructs (like top-level return, or yield) are taken care of explicitly to actually raise a SyntaxError and stay as close as possible to Python semantics.

1 Function

IPython.core.async_helpers.get_asyncio_loop()

asyncio has deprecated get_event_loop

Replicate it here, with our desired semantics:

  • always returns a valid, not-closed loop

  • not thread-local like asyncio’s, because we only want one loop for IPython

  • if called from inside a coroutine (e.g. in ipykernel), return the running loop

Added in version 8.0.