Python - Launch external program and quit script?
Question: I've wrote a little script to launch a program and send a mail if a program
has quit:

    
    
    #!/usr/bin/env python
    # coding: utf8
    
    import psutil    
    from email.mime.text import MIMEText
    from subprocess import Popen, PIPE
    import time
    import os
    
    program = "transmission-gtk"
    if not program in [psutil.Process(i).name for i in psutil.get_pid_list()]:
       try:
          os.system(program)
          text = "but it has been restarted" 
       except IOError as e:
          text = "The restart failed!\n" + e
    
       time.sleep(2)
    
       msg = MIMEText("Transmission has been closed !!\n" + text)
       msg["From"] = "adr@wmail.fr"
       msg["To"] = "adr@wmail.fr"
       msg["Subject"] = "subject"
       p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
       p.communicate(msg.as_string())
    

The script is launched by cron, every 15 min. All works, except one thing:
**transmission quit at the same moment the script quits**...

I don't want to write a permanent script (raspberry-pi), so a `while` loop is
not what I want.

Then, how to launch my program ?


Answer: You may use `os.system(program+'&')` to background the execution of your
program.

Also, even if your program works, you should have a look at the `subprocess`
module (which intends to replace `os.system()`, among other things).

