I have the following Python code:
strRunOutput = subprocess.run([strFastbootExecutable, "-s", dsn.upper(), "reboot"], timeout=5, stderr=subprocess.PIPE).stderr.decode('utf-8').upper()
Which is essentially doing this:
fastboot -s G070GV1871970FCW reboot
and this is the output:
< waiting for G070GV1871970FCW >
...which is hanging. Why the fastboot command is hanging, I don't know, but what bothers me more is that the subprocess.run command isn't timing out after 5 seconds as I told it to and is causing my program to hang. Any ideas what's going on?
Thanks!
Most of your interaction with the Python subprocess module will be via the run() function. This blocking function will start a process and wait until the new process exits before moving on. The documentation recommends using run() for all cases that it can handle.
The timeout argument is passed to Popen.communicate() . If the timeout expires, the child process will be killed and waited for. The TimeoutExpired exception will be re-raised after the child process has terminated.
The subprocess module defines one class, Popen and a few wrapper functions that use that class. The constructor for Popen takes arguments to set up the new process so the parent can communicate with it via pipes. It provides all of the functionality of the other modules and functions it replaces, and more.
The Python subprocess call() function returns the executed code of the program. If there is no program output, the function will return the code that it executed successfully. It may also raise a CalledProcessError exception.
This is a known issue - there are two tickets on the Python bug tracker relating to it.
It's not timing out because you connected a pipe.
Issue31935: subprocess.run() timeout not working with grandchildren and stdout=PIPE
Issue30154: subprocess.run with stderr connected to a pipe won't timeout when killing a never-ending shell commanad (sic)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With