trio icon indicating copy to clipboard operation
trio copied to clipboard

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

Open decentral1se opened this issue 5 years ago • 6 comments

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

decentral1se avatar Jan 08 '20 14:01 decentral1se

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.

dhirschfeld avatar Jan 08 '20 23:01 dhirschfeld

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))

mikenerone avatar Mar 16 '24 02:03 mikenerone

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

jakkdl avatar Mar 16 '24 08:03 jakkdl

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?

mikenerone avatar Mar 16 '24 17:03 mikenerone

@mikenerone I saw you comment here and have added a reference to IPython in the docs on #2972 https://github.com/python-trio/trio/blob/2551d049061126b1998c9b93d60f2b481864bf31/docs/source/reference-core.rst#L1951

clint-lawrence avatar Mar 17 '24 23:03 clint-lawrence

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

Awesome, thanks much!

mikenerone avatar Mar 18 '24 01:03 mikenerone