zzandy zzandy - 1 month ago 9
Python Question

How to start daemon process from python on windows?

Can my python script spawn a process that will run indefinitely?

I'm not too familiar with python, nor with spawning deamons, so I cam up with this:

si = subprocess.STARTUPINFO()
si.dwFlags = subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.CREATE_NEW_CONSOLE
subprocess.Popen(executable, close_fds = True, startupinfo = si)

The process continues to run past python.exe, but is closed as soon as I close the cmd window.


Using the answer Janne Karila pointed out this is how you can run a process that doen't die when its parent dies, no need to use the win32process module.

subprocess.Popen(executable, creationflags=DETACHED_PROCESS, close_fds=True)