Is there a way to PASS a command timeout
option to proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
to terminate commands that are hung indefinitely
import signal, os
import sys
import subprocess
import argparse
from subprocess import Popen, PIPE, STDOUT
import threading
from time import sleep
import time
from subprocess import Popen, PIPE, STDOUT
cmd = "python script.py -m loc"
proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
print "Executing %s"%cmd
with proc.stderr:
for line in iter(proc.stderr.readline, b''):
print line,
print "process is done..." #doesn't print when command is hung
UPDATE:-
I looked at the following tickets,I dont find a clear example on how to use subprocess32
,I googled around in python docs,still cant find