I am an electrical engineer trying to do multiprocessing in python2.7. I have two oscilloscopes which need to run the same tests on 2 different signals.
Right now, I have a code which does it in sequence and takes long time.
I want to make the measurements simultaneously on both scopes and put the results into logging function, one after the other properly.
I am trying to dabble with the multiprocessing or concurrent.futures which ever helps me.
Here is the point where I need help.
My tests are python functions
def test1(scope_num):
recall_setup() #talk to scope over network
a = read_measurments()
return a
def test2(scope_num):
recall_setup() #talk to scope over network
a = read_measurments()
return a
Below is my main loop
scope1=scipycmd(ip_addr_1)
scope2=scipycmd(ip_addr_2)
def control_prog():
result=emptyclass()
for temperature in [0,25,100]:
for voltage in [600,700,800]:
init_temp_volt(temperature, voltage)
for scope in [scope1,scope2]:
result.test1 = test1(scope)
result.test2 = test2(scope)
logfile.write_results(results)
control_prog()
Q1. How do I make it to parallel process scope1 and scope2 simultaneously?
Q2. How to handle logging?
Will be very helpful if anybody can guide me
EDIT: OK.. I tried both multiprocess and multithread approach, and multiprocess approach is the fastest (obviously). But now logging is still a problem.
What I tried
scope=([scope0],[scope1])
def worker():
test1()
test2()
def mp_handler(var1):
for indata in var1:
p = multiprocessing.Process(target=worker, args=(indata[0]))
p.start()
Executes beautifully, but logging is not working.
Q1 answer:
Here is the link to the python thread docs