How can I check, from a Python script, if another specific Python script is running?
def running():
for q in psutil.process_iter():
print q
if q.name() == 'server_class.py':
return True
return False
I have tried that but the program is called "python" and not the name of the script.
The python script file will be part of the command line. You can try something along these lines:
def running():
for q in psutil.process_iter():
if q.name() == 'python':
print q.cmdline()
if len(q.cmdline())>1 and 'server_class.py' in q.cmdline()[1]:
return True
return False
I am using in just for the example. You might want to match the full path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With