Last active
March 18, 2019 07:13
-
-
Save chrisseto/8f7289497f40ad442a30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.core.magic import Magics, magics_class, line_magic | |
import asyncio | |
@magics_class | |
class AsyncMagics(Magics): | |
@line_magic | |
def await(self, line): | |
return asyncio.get_event_loop().run_until_complete(eval(line, self.shell.user_global_ns, self.shell.user_ns)) | |
def load_ipython_extension(ipython): | |
ipython.register_magics(AsyncMagics) |
My ipython does not have %install_ext
, I had to copy it into ~/.ipython/extensions/await.py
. To autoload it on every start, you can set the following in the config file (probably ~/.ipython/profile_default/ipython_config.py
):
c = get_config()
c.InteractiveShellApp.extensions = [
'await'
]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could we make this pip installable, say as package "ipython-await-magics" (analogous to https://pypi.python.org/pypi/ipython-pip-magics)?
The reason I'm asking is because IPython deprecated %install_ext (ipython/ipython#8601). The recommended way of doing things is pip, apparently.
I would volunteer to do it. In that case, I guess you'd have to attach a license to await.py so I can use it.
(update: @chrisseto and @rickardraysearch, did you get notified about this?)