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

Addclose() method toasyncio.StreamReader #130925

Open
Labels
@rianhunter

Description

@rianhunter

Feature or enhancement

Proposal:

When creating a sub-process usingasyncio.create_subprocess_exec(), it returns aProcess instance that has astdout property. This property is intended to be an asyncio version of thestdout property of thePopen instance from thesubprocess module.

An important aspect ofPopen.stdout property is that you can close it. This is a signal to the sub-process that is generating output that it should cleanly terminate. This is a common pattern in processes used in shell pipelines. Indeed, the object located atPopen.stdout has aclose() method. This pattern is demonstrated below:

importsubprocessproc=subprocess.Popen(["yes"],stdout=subprocess.PIPE)# start subprocessdata=proc.stdout.read(4096)# get dataproc.stdout.close()# signal to process to cleanly shutdownproc.wait()# wait for shutdown

Unfortunately this pattern cannot be reproduced easily with thestdout property of theProcess instance returned fromasyncio.create_subprocess_exec() becausestdout is an instance ofStreamReader which does not have theclose() method.

I propose adding aclose() method to theStreamReader class so that asyncio version of thesubprocess module may support this pattern of managing sub-processes. This change is consistent with the asyncio ecosystem as the companionStreamWriter class already has aclose() method, along with other methods that expose its inner "transport" object. It's also trivial to implement, since it's essentially a wrapper method around the inner transport object'sclose() method.

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp