How to start daemon process from python on windows?

前端 未结 3 1034
眼角桃花
眼角桃花 2020-12-08 17:10

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:



        
3条回答
  •  生来不讨喜
    2020-12-08 17:45

    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.

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

    DETACHED_PROCESS is a Process Creation Flag that is passed to the underlying CreateProcess function.

提交回复
热议问题