proc communicate not exiting on python subprocess timeout - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: proc communicate not exiting on python subprocess timeout (/thread-4979.html) |
proc communicate not exiting on python subprocess timeout - leoonardoo - Sep-13-2017 Hello, the script below (a python process is called, which calls a waitfor cmd with a timeout of 4 seconds) is supposed to end after 4 seconds. But instead proc.communicate stops after the 20 seconds timeout. Why??? import subprocess if __name__ == "__main__": proc_str = ["C:\\Program Files (x86)\\Anaconda3\\Python.exe", "-c", "import subprocess;subprocess.run('cmd /S /C waitfor g /t 200', shell=False, timeout=4)"] proc = subprocess.Popen(proc_str, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, universal_newlines=True) (proc_out, proc_err) = proc.communicate(timeout=20) if (proc.returncode == 0): pass |