user2149071
user2149071

Reputation: 69

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

Upvotes: 0

Views: 48

Answers (1)

v2b
v2b

Reputation: 1456

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

Upvotes: 2

Related Questions