I was to make a launcher application, I haven't found a way to detach a sub-process entirely from the spawning python process.
When I launch a program with my desktop's (cinnamon's) launcher the process tree goes:
/sbin/init -> mdm -> mdm -> cinnamon-session -> cinnamon -> the-app-i-launched
Of the threads I read, this one was the most insightful/helpful: Launch a completely independent process. But gets muddied answers as the OP is looking to run python code, which can often be achieved in many usually-preferred ways than by spawning an independent process.
From other posts from stack overflow that do not answer how to launch a detatched python process:
close_fds=True
on linux, process spawns as a child of the python process.ValueError: creationflags is only supported on Windows platforms
.nohup
: Process spawns as a child of the python process. As far as I know, nohup
or equivalent is not available on all platforms, making it a linux-only solution.AttributeError: 'module' object has no attribute 'P_DETACH'.
A working solution can be found in JonMc's answer here. I use it to open documents using 'xdg-open'.
You can change the stderr argument to stderr=open('/dev/null', 'w'),
if you do not want a logfile.