Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Description
Feature or enhancement
Proposal:
The asyncio module's runnable module behaves a lot like the regular interpreter, but is missing the-c option. This would be useful in using (as in: sharing them as minimal reproducers, or for feature probing in CI) little snippets of asyncio code without defining a function that's sent through asyncio.run.
Example that I'd like to see work:
$python3 -m asyncio --help[...]options: -h, --help show this help message and exit -c cmd program based passed in as a string, evaluated like the body of an async function that is run to completion (terminates option list)$python3 -m asyncio -c'await asyncio.sleep(1)'$python3 -m asyncio -c'print(await asyncio.get_event_loop().getaddrinfo("::1", 1234))'
Minor questions
Should the asyncio module be auto-imported? Probably yes, because this give the parity between "I pass something in to -c" and "I put something in the interactive interpreter" (which, in asyncio, also loads that module)
Should there be a more explicit warning when someone tries to do
python3 -m asyncio -c 'asyncio.sleep(1)(which does not await the future), or does the automatic ":1: RuntimeWarning: coroutine 'sleep' was never awaited" suffice?Should we also accept
-iand-qfor consistency? (Unlike the main CLI, asyncio always behaves as if-iwas passed in, as evidenced by comparingdd | python3 -m asyncio/import this/ Ctrl-D anddd | python3/import this/ Ctrl-D).That'd complete the list of options that it'd make sense to replicate under
-m; the other options apply "through"-m asyncioand thus don't need to be duplicated. (Except-m, but that doesn't make any sense to nest).
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
Projects
Status