-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
Add __main__
module with await
-compatible console
#2407
Closed
Closed
Commits on Aug 26, 2022
-
Add
__main__
module withawait
-compatible consoleI recently learned that `python -m asyncio` drops you into an interpreter session that knows how to deal with `await` expressions. For example, ```console $ python -m asyncio asyncio REPL 3.10.6 [...] on darwin Use "await" directly instead of "asyncio.run()". Type "help", "copyright", "credits" or "license" for more information. >>> import asyncio >>> await asyncio.sleep(1); print("hi") # prints after one second hi ``` This quickly became an important part of my async debugging toolbox. I've also been learning Trio recently, but I've been missing my async console. This PR takes the script from [`asyncio.__main__`][1] and adapts it to use a Trio run loop. With this patch applied, users can run `python -m trio` to drop into an interactive interpreter session that lets them directly `await` Trio-based async expressions. ```console $ python -m trio Trio 0.21.0+dev, Python 3.10.6 [...] on darwin Use "await" directly instead of "trio.run()". Type "help", "copyright", "credits" or "license" for more information. >>> import trio >>> await trio.sleep(1); print("hi") # prints after one second hi ``` [1]: https://github.com/python/cpython/blob/master/Lib/asyncio/__main__.p I'm very new to Trio, so I'm sure my approach is suboptimal. In particular, I'd really appreciate feedback from the team/ community on: - not using `threading` with a brand new `trio.run` to evaluate awaitable expressions. I found that if I simply used `self.nursery.start_soon` in the same thread as `runcode`, `await` expressions wouldn't get the chance to be evaluated until the session was shutting down (might have been blocked by reading keyboard input, if I had to guess). Could there be a solution in `trio`'s threading tools? - what documentation updates should accompany this PR - what sort of tests I should add (since this change implements a brand new code path that won't be touched by any existing or future usage of `trio` itself, I wasn't sure if it would even be appropriate to _try_ and test it) - anything else to align this addition to the Trio way! Many thanks for your consideration.
Configuration menu - View commit details
-
Copy full SHA for 7cbd170 - Browse repository at this point
Copy the full SHA 7cbd170View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5679cc9 - Browse repository at this point
Copy the full SHA 5679cc9View commit details
Commits on Aug 27, 2022
-
Adds a section to the end of the reference-core document that notes the existence of this new feature, what it's for, and how to use it. Fixes the broken `:mod:` link from my towncrier entry by instead linking to the new section in reference-core.
Configuration menu - View commit details
-
Copy full SHA for bb6e6df - Browse repository at this point
Copy the full SHA bb6e6dfView commit details -
Configuration menu - View commit details
-
Copy full SHA for fa688a4 - Browse repository at this point
Copy the full SHA fa688a4View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7d17fb5 - Browse repository at this point
Copy the full SHA 7d17fb5View commit details
Commits on Sep 3, 2023
-
Configuration menu - View commit details
-
Copy full SHA for fc28bbf - Browse repository at this point
Copy the full SHA fc28bbfView commit details
Commits on Oct 31, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 928865c - Browse repository at this point
Copy the full SHA 928865cView commit details -
Configuration menu - View commit details
-
Copy full SHA for df22756 - Browse repository at this point
Copy the full SHA df22756View commit details
Commits on Nov 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 0c645e1 - Browse repository at this point
Copy the full SHA 0c645e1View commit details -
Configuration menu - View commit details
-
Copy full SHA for ce70b35 - Browse repository at this point
Copy the full SHA ce70b35View commit details -
Configuration menu - View commit details
-
Copy full SHA for 87d869b - Browse repository at this point
Copy the full SHA 87d869bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 29d232e - Browse repository at this point
Copy the full SHA 29d232eView commit details -
Configuration menu - View commit details
-
Copy full SHA for a9fd6cc - Browse repository at this point
Copy the full SHA a9fd6ccView commit details
Commits on Jan 9, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 3f73ce5 - Browse repository at this point
Copy the full SHA 3f73ce5View commit details
Commits on Feb 20, 2024
-
Configuration menu - View commit details
-
Copy full SHA for a43a9f3 - Browse repository at this point
Copy the full SHA a43a9f3View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.