![](/img/trans.png)
[英]How do I detect if my Python script is running in the 'Windows Terminal'
[英]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.