[issue22239] asyncio: nested event loop

Douglas Raillard report at bugs.python.org
Thu Aug 19 10:22:25 EDT 2021


Douglas Raillard <douglas.raillard at arm.com> added the comment:

Drive by comment: I landed on this thread for the exact same reason:
> This situation is very frequent when e.g. a library is designed to be async-first, and also provides a blocking API which just wraps the async code by running it until complete.

The library in question is "devlib", which abstracts over SSH/adb/local shell. We cannot make a "full" switch to async as it would be a big breaking change. To workaround that, I came up with a decorator that wraps a corountine, and "replaces" it such that:

    @asyncf
    async def f(...):
        ...

    # Blocking call under its "normal" name, for backward compat
    f()

    # Used in an async environment
    await f.asyn()

This allows converting bit by bit the whole library, with full backward compatibility for both users and internal calls.

On top of that, that library is heavily used in jupyter notebooks, so all in all, nest-asyncio is impossible to avoid.

----------
nosy: +douglas-raillard-arm

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22239>
_______________________________________


More information about the Python-bugs-list mailing list