bash - Python, run a shell script as soon as the previous iteration ends. -
i trying write simple program call shell script. need shell script executed continuously, however, not in given time interval, since can't know how long take process created shell script finish. have used threading run script every n seconds. need is, "test.sh" ends, run "test.sh" again.
this current code.
import subprocess import threading looptime = 7.0 def recognize(): threading.timer(looptime,recognize).start() filepath = "/home/user/downloads/image.jpg" output = subprocess.check_output(['dir/test.sh',str(filepath)]) print ("python print\n%s" % output) recognize()
you don't need threading.timer
. subprocess.check_output
will block main process until child process finished.
import subprocess def recognize(): filepath = "/home/user/downloads/image.jpg" output = subprocess.check_output(['dir/test.sh',str(filepath)]) print ("python print\n%s" % output) while true: recognize()
Comments
Post a Comment