Run background process in Python and do NOT wait

后端 未结 3 2198
佛祖请我去吃肉
佛祖请我去吃肉 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:19

    Here is verified example for Python REPL:

    >>> import subprocess
    >>> import sys
    >>> p = subprocess.Popen([sys.executable, '-c', 'import time; time.sleep(100)'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); print('finished')
    finished
    

    How to verify that via another terminal window:

    $ ps aux | grep python
    

    Output:

    user           32820   0.0  0.0  2447684   3972 s003  S+   10:11PM   0:00.01 /Users/user/venv/bin/python -c import time; time.sleep(100)
    

提交回复
热议问题