简体   繁体   中英

How to detect a running script on windows?

I have a simple script running on windows background. I will start it when something happen.how can i detect is there the script is running?

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()

You can use the isAlive method on the thread to check if it is already running. On similar lines, if you were running a process instead, then you could write a pid file everytime you start the process and query the OS for the status of that specific pid anytime you required.

Check the following link for more on isAlive.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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