trio
trio copied to clipboard
Provide "python -m trio" to drop into trio based REPL
Just like "python -m asyncio" so we can use things like "await foo" straight out of the box.
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.
In case you're using IPython you can use the
%autoawait triomagic 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))
that sounds like something super useful that should be added to the docs somewhere
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 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
@mikenerone I saw you comment here and have added a reference to IPython in the docs on #2972
Awesome, thanks much!