我是一名电气工程师,尝试在python2.7中进行多重处理。 我有两个示波器,需要运行两个不同的信号相同的测试。你知道吗
现在,我有一个按顺序执行的代码,需要很长时间。你知道吗
我想在两个示波器上同时进行测量,并将结果一个接一个地正确地放入日志函数中。你知道吗
我正试着涉猎多处理或期货这对我很有帮助。你知道吗
这是我需要帮助的地方。你知道吗
我的测试是python函数
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
下面是我的主循环
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()
问题1。如何同时并行处理scope1和scope2?你知道吗
问题2。如何处理日志记录?你知道吗
如果有人能指导我会很有帮助的
编辑:确定。。 我尝试了多进程和多线程两种方法,显然多进程方法是最快的。但是现在日志仍然是一个问题。你知道吗
我试过的
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()
执行得很漂亮,但日志记录不起作用。你知道吗
比如:
问题1答案:
Here is the link to the python thread docs
相关问题 更多 >
编程相关推荐