线程事件发生时如何暂停和恢复主连续循环?

问题描述

我在主代码中有一个无限的while循环,该循环不断从某个工具收集数据。我还有一个线程事件,每15分钟在同一台仪器上运行一次不同类型的配置。 (我从Improve current implementation of a setInterval获得了线程解决方案)但是,当发生线程事件时,主while循环仍在运行,这使仪器感到混乱,因为现在正在向其传递两种不同的配置。以下是我的代码

<!DOCTYPE html>
<html>
<head>
<title> @R_90_4045@ion </title>
</head>
<body>
<h1> World of Red Dead Redemption II</h1>
</body>
</html>

当带有from threading import Event,Thread def call_repeatedly(interval,func,*args): stopped = Event() def loop(): while not stopped.wait(interval): # the first call is in `interval` secs func(*args) Thread(target=loop).start() return stopped.set def config2(x,y,z): #sets instrument to configuration2 using x,z arguments and runs cancel_future_calls = call_repeatedly(900,config2,x,z) start_time=time.time() #main loop: while True: #configure instrument with some settings and acquire data #save data to excel file with a timestamp to the data workbook[worksheet].append([divmod(divmod(time.time()-start_time,3600)[1],60)[0],acquired_data1,acquired_data2]) workbook.save(filename) 的线程事件发生时,如何暂停主while循环的操作,而当config2(x,z)完成时如何恢复?我已经检查了这里的一些解决方案,但都建议在主函数中使用config2(x,z),但是由于我必须在主while循环中连续获取数据,所以我无法做到这一点。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)