Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing configuration to IPython.embed and IPython.embed_kernel #12229

Open
eric-wieser opened this issue Apr 10, 2020 · 3 comments
Open

Passing configuration to IPython.embed and IPython.embed_kernel #12229

eric-wieser opened this issue Apr 10, 2020 · 3 comments

Comments

@eric-wieser
Copy link
Contributor

eric-wieser commented Apr 10, 2020

Apologies if this is the wrong place to ask this, I tried on the gitter but it doesn't seem particularly active.

I'm trying to create an embedded ipython with a custom async loop runner. My naive attempt is something like:

import IPython
from traitlets.config import Config
c = Config()
c.InteractiveShell.loop_runner = print  # not a real runner, but enough to debug
IPython.embed(config=c)

but in the shell, get_ipython().loop_runner is still set to IPython.core.async_helpers._pseudo_sync_runner.

Am I setting the config wrongly, or is this config special and somehow harder to set?

Possibly a duplicate of #10724

@Carreau
Copy link
Member

Carreau commented Apr 13, 2020

Something like that ?

import IPython

def trio_runner(async_fn):
    import trio

    async def loc(coro):
        """
        We need the dummy no-op async def to protect from
        trio's internal. See https://github.com/python-trio/trio/issues/89
        """
        return await coro
    print('Running with my runner')
    return trio.run(loc, async_fn)


IPython.embed(using=trio_runner)
$ python foo.py
Python 3.8.1 | packaged by conda-forge | (default, Jan 29 2020, 15:06:10)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.0.dev -- An enhanced Interactive Python. Type '?' for help.

In [1]: import trio

In [2]: await trio.sleep(1)
Running with my runner

In [3]:

embed() is a bit weird and overwrite the config because of nesting.

@eric-wieser
Copy link
Contributor Author

Where can I find documentation of the using argument?

That looks promising, thanks!

@eric-wieser
Copy link
Contributor Author

Thanks for the help, your example solved my issue.

In the end though, I needed extra configuration so used the IPython.terminal.embed.InteractiveShellEmbed constructor.

Probably still worth leaving this issue open as a documentation issue about describing using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants