Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
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
Projects
Status