所以我用pyinstaller -w myscript来制作我的python的可执行文件,但是效果很好,但是现在我想运行该exe,但前提是它尚未运行
我已经尝试过添加到问题中的代码,它不会运行,因为该进程是在执行时完成的,因此在检查时返回true,因此它不会运行。 我希望能够做到这一点而无需在磁盘上写入任何内容,说嘿我已经在运行。布尔
import psutil
def checkIfProcessRunning(processName):
'''
Check if there is any running process that contains the given name processName.
'''
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
def main():
if checkIfProcessRunning('Logout Script'):
print('Yes a chrome process was running')
else:
print('No chrome process was running')
main()
预期结果是在任何给定时间仅存在一个实例