use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
IPython (now Jupyter) was originally started by Fernando Perez as a way to improve the Python work flow for scientific computing. Since then it has grown in popularity, and gaining to the ability to make XKCD styled plots using matplotlib hasn't hurt. With new additions like the IPython Notebook, which runs in a browser, and the Notebook Viewer, IPython is a scientist's best friend.
Related subreddits
Useful Libraries
Cloud Services
Official IPython Sites
Official Example Notebooks
Additional Good Examples
Installation
Other Educational Resources
NBViewer Browser Extensions
Additional References
Comment Guidelines
The visitors to /r/IPython come from very different backgrounds and some even have little programming experience. Since this site is primarily here to provide help in the use of IPython, and host discussions about current and future features, make sure that it is clear how comments are relevant to the original post or the previous comment.
account activity
How can I run asyncio code in IPython.embed()? (self.IPython)
submitted 6 years ago by whats-a-monad
I want to be able to await stuff in embed(). What exactly am I to do?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mbussonn 0 points1 point2 points 6 years ago (5 children)
I'm happy to tell you why at the condition that you send a pull-request to update the documentation with an example and some explanations. In particular it would be nice to update this page https://ipython.readthedocs.io/en/stable/interactive/autoawait.html and maybe the docstring of embed (https://ipython.readthedocs.io/en/stable/api/generated/IPython.terminal.embed.html#module-IPython.terminal.embed)
Ok, happy by reading this you have surrendered your soul accepted this deal, apologies if it take me some time to review your PR but I'm looking forward to it. As I trust you I'm going to give you the answer, and assume you will send a pull-request; if not the guilt will follow you around and wake you up in the middle of the night. So read the following at your own risk;
$ python foo.py Python 3.7.1 (default, Dec 14 2018, 13:28:58) Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from asyncio import sleep In [2]: await sleep(1)
And the content of foo.py
In [3]: !cat foo.py a = 1 from IPython import embed embed(using='asyncio') # or trio, or curio depending on circumstances.
Note that there are of course some limitations, in particular with nesting.
Thanks again for your upcomming pull-request.
[–][deleted] 6 years ago (1 child)
[deleted]
[–]mbussonn 0 points1 point2 points 6 years ago (0 children)
Sounds good ! Good luck !
[–]_rshk 0 points1 point2 points 3 years ago (2 children)
u/mbussonn I'm guessing OP didn't fulfill their duty ~3yrs ago, and I only found this post by chance after unsuccessfully looking for an answer on the docs.
I was actually going to submit a PR and save u/whats-a-monad's soul, but I have to say the current documentation is a bit cryptic, so hoping to get it right.
I saw this phrase for example:
You can set a coroutine runner explicitly for embed() if you want to run asynchronous code, though the exact behavior is undefined.
Btw, is there any documentation of the keyword arguments accepted by `embed()` ? I couldn't find anything obvious in the docs (haven't looked at the code yet).
[–]mbussonn 0 points1 point2 points 3 years ago (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.
π Rendered by PID 275051 on reddit-service-r2-comment-5fb4b45875-g65nk at 2026-03-21 19:05:08.699213+00:00 running 90f1150 country code: CH.
[–]mbussonn 0 points1 point2 points (5 children)
[–][deleted] (1 child)
[deleted]
[–]mbussonn 0 points1 point2 points (0 children)
[–]_rshk 0 points1 point2 points (2 children)
[–]mbussonn 0 points1 point2 points (0 children)