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.
Reproduction:
Create count.sh
function count {
for i in 1 2 3 4 5;
do
sleep 1
echo "$i" >&2
done
}
count &
echo "Done" >&2
Result:
subprocess.TimeoutExpired: Command '['/bin/bash', './count.sh']' 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", "./count.sh"], 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
The text was updated successfully, but these errors were encountered:
piwicode commentedSep 21, 2022
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.
Reproduction:
Create count.sh
Reproduce with:
Result:
subprocess.TimeoutExpired: Command '['/bin/bash', './count.sh']' 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", "./count.sh"], timeout=1)
works as expected, that is to sayrun
returns immediately.Environment:
Python 3.8.9:
The text was updated successfully, but these errors were encountered: