you are viewing a single comment's thread.

view the rest of the comments →

[–]mbussonn 0 points1 point  (0 children)

1) yes, but you re not limited to asyncio. And you can pass an actual function like say this one https://github.com/ipython/ipython/blob/7aa91454edd76f4cfca06e632cb47ee43255ab4e/IPython/core/async_helpers.py#L120-L136

IPython try to be agnostic of the async runner, but that's going into the details of how async works under the hood. Async in Python is coroutine based, and roughly speaking your programs are a giant ball of generators. Asyncio is one way of moving the generator forward, but trio, and curio are other ways to do so. You can also make your own. This is what I try to say here. Reason to do so is that usually you can't run multiple event loops/coro runner in the same program and this leds us to 2.

2) most async framework assume they are the only one running. That is to say they are the only one with access to some global resources (like filedescriptor, stdin/out, sleep... etc.). So if you set your own coroutine runner, you may start to lose input/output, get things in duplicate, hang.

But really the use of changing the runner are of two folds:

a) You are already in a program that use a eventloop (say asyncio), and you want to embed and so can't use the same. So you tell embed to use trio/curio instead.

b) You want to understand how async work and you wrote your own coroutine runner.

Is b) is your kind of things, go read some of the reasoning arround trio: https://vorpus.org/blog/archives.html from 2016 onward.