Run python script only if it's not running
Question: I want to launch a python script from another python script. I know how to do
it. But I should launch this script only if it is not running already.

**code:**

    
    
    import os
    os.system("new_script.py")
    

But I'm not sure how to check if this script is already running or not.


Answer: Try this:

    
    
    import subprocess
    import os 
    
    p = subprocess.Popen(['pgrep', '-f', 'your_script.py'], stdout=subprocess.PIPE)
    out, err = p.communicate()
    
    if len(out.strip()) == 0:
        os.system("new_script.py")
    

