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

Provide "python -m trio" to drop into trio based REPL #1360

Closed
decentral1se opened this issue Jan 8, 2020 · 6 comments · Fixed by #2972
Closed

Provide "python -m trio" to drop into trio based REPL #1360

decentral1se opened this issue Jan 8, 2020 · 6 comments · Fixed by #2972

Comments

@decentral1se
Copy link
Member

decentral1se commented Jan 8, 2020

Just like "python -m asyncio" so we can use things like "await foo" straight out of the box.

@dhirschfeld
Copy link
Member

In case you're using IPython you can use the %autoawait trio magic command to await things at the interactive prompt - it works great and is very cool!

...doesn't mean that python -m trio wouldn't also be useful for those who don't want to drag in all the IPython deps.

@mikenerone
Copy link
Member

In case you're using IPython you can use the %autoawait trio magic command to await things at the interactive prompt - it works great and is very cool!

Related tip: Adding this to your IPython profile will automatically turn on Trio mode if it's installed in your current environment. If not, it will try applying nest_asyncio (if it's installed) in case you want to do asyncio stuff without breaking IPython. It pretty much means you don't have to think about setting up your async IPython mode anymore.

~/.ipython/profile_default/startup/10-async.py

msgs = [""]

try:
    import trio
    get_ipython().run_line_magic("autoawait", "trio")
    msgs.append("Trio-mode %autoawait")
except ImportError:
    try:
        import nest_asyncio
        nest_asyncio.apply()
        msgs.append("(nest-asyncio patch applied)")
    except ImportError:
        pass

print("\n".join(msgs))

@jakkdl
Copy link
Member

jakkdl commented Mar 16, 2024

that sounds like something super useful that should be added to the docs somewhere

@mikenerone
Copy link
Member

mikenerone commented Mar 16, 2024

that sounds like something super useful that should be added to the docs somewhere

Happy to add it - I think it would make sense as a paragraph or sidebar in the Interactive Debugging section that's already part of #2972. If we think that's going to land, I can add a commit to that branch. wdyt?

Also, would you agree that I should remove the nest-asyncio support for the purpose of Trio docs?

@clint-lawrence
Copy link
Contributor

@mikenerone I saw you comment here and have added a reference to IPython in the docs on #2972

If you are an IPython user, you can use IPython's `autoawait

@mikenerone
Copy link
Member

mikenerone commented Mar 18, 2024

@mikenerone I saw you comment here and have added a reference to IPython in the docs on #2972

Awesome, thanks much!

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

Successfully merging a pull request may close this issue.

6 participants