Skip to content

asyncio.create_subprocess_shell() cannot be killed if command contains a pipe #127874

@n-peugnet

Description

@n-peugnet

Bug report

Bug description:

I am trying to run a subprocess shell command using asyncio.create_subprocess_shell() and then kill it after some amount of time.
When the command contains a pipe, then the subprocess is impossible to kill from within python. It can still be killed from the outside obviously (e.g. the kill command).

Here is a code that exhibits this behaviour:

import asyncio

async def test():
    proc = await asyncio.create_subprocess_shell("yes | while read l; do sleep 1; echo $l; done")
    await asyncio.sleep(1)
    proc.kill()
    await proc.wait()

asyncio.run(test())

A similar command, without a pipe, can be killed, for example: "while true; do sleep 1; echo test; done"

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions