![](/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.