更新时间:2022-06-12 05:25:40
尝试在script.sh之前添加 nohup 。您可能需要决定如何处理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)