subprocess.run keeps waiting after the process termination
@gpshead is already working on this.
Since Oct 23, 2022.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
subprocess.run keeps waiting after the process termination.
This happens when stdout or stderr is redirected, and the started process pass that stream to a background process.
Reproduce with:
import subprocess
subprocess.run(["/bin/bash", "-c", "sleep 5&"], stdout=subprocess.PIPE, timeout=1)
Result:
subprocess.TimeoutExpired: Command '['/bin/bash', '-c', 'sleep 5&']' timed out after 1 seconds
This is not correct as the subprocess has terminated and produces a return code.
The expected behavior for run is to return as soon as the instanciated terminates, regardless of the streams lifecycles.
Variants:
Calling subprocess.run(["/bin/bash", "-c", "sleep 5&"], timeout=1) works as expected, that is to say run returns immediately.
Environment:
Python 3.8.9:
- CPython versions tested on:
- Operating system MacOs, Linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.