Monday, 15 March 2010

raspberry pi - running two subprocesses simultaneously from python module -



raspberry pi - running two subprocesses simultaneously from python module -

i trying execute 2 sub-processes @ same time python module on raspberry pi. sec process has wait first 1 finish before starts wondering if there way have both of them started @ same time. info beingness read in gives line every 5 seconds, , 2 .sh programs not take more sec each finish. if have suggestions on how or if there work around appreciated. code below:

f = open("testv1.txt", "a") import serial import subprocess ser = serial.serial('/dev/ttyacm0', 115200) while 1: x= ser.readline() subprocess.call(['./camera1.sh'],shell=true) subprocess.call(['./camera2.sh'],shell=true) print(x) f.write(str(x))

so changed code does:

cam1 = subprocess.popen("./camera1.sh") cam2 = subprocess.popen("./camera2.sh")

but getting next errors:

traceback (most recent phone call last): file "/home/pi/desktop/doyle/capturev1/testv1.py", line 7, in <module> cam1 = subprocess.popen("./camera1.sh") file "/usr/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) file "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child raise child_exception oserror: [errno 8] exec format error

any other suggestions on how prepare it?

you need utilize popen constructor execute kid programme in new process. in way can have 2 threads doing @ same time.

try like:

###somecode cam1 = subprocess.popen("./camera1.sh") cam2 = subprocess.popen("./camera2.sh") ###othercode

be careful manage threads correctly. after call, it's thing check if kid processes have terminated whith method poll() or wait:

cam1.wait() #wait until kid terminates cam1.poll() #return status of kid process.

python-2.7 raspberry-pi

No comments:

Post a Comment