且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Python 中生成一个新的独立进程

更新时间:2022-06-12 05:26:04

尝试在前面加上 "nohup" 到 script.sh.您可能需要决定如何处理 stdout 和 stderr;我只是把它放在示例中.

Try prepending "nohup" to script.sh. You'll probably need to decide what to do with stdout and stderr; I just drop it in the example.

import os
from subprocess import Popen

devnull = open(os.devnull, 'wb') # Use this in Python < 3.3
# Python >= 3.3 has subprocess.DEVNULL
Popen(['nohup', 'script.sh'], stdout=devnull, stderr=devnull)