我是学徒开发人员,我的公司要求我开发一些“插件”来进行培训。
我创建了一个进程,该进程每5秒检查一次从站是否启用。
在我的主脚本上,如果要启用从属,我希望他显示绿色图片,如果禁用则要红色。
我不知道过程检查器应该发送哪种信号以及如何获得它。我在界面上使用PyQt5。
过程检查器如下所示:
import time, traceback
import psutil
import threading
from PyQt5.QtCore import QObject, pyqtSignal
def every(delay, task):
next_time = time.time() + delay
while True:
time.sleep(max(0, next_time - time.time()))
try:
task()
except Exception:
traceback.print_exc()
# in production code you might want to have this instead of course:
# logger.exception("Problem while executing repetitive task.")
# skip tasks if we are behind schedule:
next_time += (time.time() - next_time) // delay * delay + delay
def checkIfProcessRunning(processName='deadlineslave', QObject):
'''
Check if there is any running process that contains the given name processName.
'''
# Iterate over the all the running process
slaveActif = False
for proc in psutil.process_iter():
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
slaveActif = True
break
if slaveActif:
print("yes")
else:
print("no")
threading.Thread(target=lambda: every(5, checkIfProcessRunning)).start()
目前,如果启用了slave,他还给我了。
谢谢 Pixidream (英语不是我的主要语言:/)