Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

-m asyncio -c 'await foo' #144958

Open
Open
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement
@chrysn

Description

@chrysn

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 dopython3 -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-i and-q for consistency? (Unlike the main CLI, asyncio always behaves as if-i was 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 asyncio and 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

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp