Python spawn off a child subprocess, detach, and exit

For Python 3.8.x, the process is a bit different. Use the start_new_session parameter available since Python 3.2:

import shlex
import subprocess

cmd = "<full filepath plus arguments of child process>"
cmds = shlex.split(cmd)
p = subprocess.Popen(cmds, start_new_session=True)

This will allow the parent process to exit while the child process continues to run. Not sure about zombies.

The start_new_session parameter is supported on all POSIX systems, i.e. Linux, MacOS, etc.

Tested on Python 3.8.1 on macOS 10.15.5

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)