繁体   English   中英

如何在Windows上检测正在运行的脚本?

[英]How to detect a running script on windows?

我有一个在Windows背景上运行的简单脚本。 当事情发生的时候我会启动它。我能检测到脚本是否在运行?

import threading
def sayhello():
    print "hello world"
    global t        #Notice: use global variable!
    t = threading.Timer(5.0, sayhello)
    t.start()

t = threading.Timer(5.0, sayhello)
t.start()

您可以在线程上使用isAlive方法来检查它是否已在运行。 在类似的行上,如果您正在运行一个进程,那么每次启动进程时都可以编写一个pid文件,并在需要时随时向操作系统查询该特定pid的状态。

有关isAlive的更多信息,请查看以下链接。

http://docs.python.org/2/library/threading.html#threading.Thread.isAlive

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM