Run background process in Python and do NOT wait

后端 未结 3 2146
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 08:21

My goal is simple: kick off rsync and DO NOT WAIT.

Python 2.7.9 on Debian

Sample code:

rsync_cmd = \"/usr/bin/rsync -a -e \'ssh -i /home/myus         


        
3条回答
  •  情歌与酒
    2020-11-29 09:15

    I encountered a similar issue while working with qnx devices and wanted a sub-process that runs independently of the main process and even runs after the main process terminates. Here's the solution I found that actually works 'creationflags=subprocess.DETACHED_PROCESS':

    import subprocess
    import time
    
    pid = subprocess.Popen(["python", "path_to_script\turn_ecu_on.py"], creationflags=subprocess.DETACHED_PROCESS)
    
    time.sleep(15)
    print("Done")
    

    Link to the doc: https://docs.python.org/3/library/subprocess.html#subprocess.Popen

提交回复
热议问题