Call a python subprocess as daemon and exit

前端 未结 2 777
旧时难觅i
旧时难觅i 2021-01-04 01:23

I\'m using a pair of python programs, one of which should call the second.

But this should be done in a way that the first program makes the second one a daemon (or

2条回答
  •  醉梦人生
    2021-01-04 02:01

    A "daemon" carries a more specific definition than just "background process". By default Popen will execute a subprocess and give control back to your program to continue running. However, that says nothing about dealing with signals (notably, SIGHUP if the user exits their shell before your background process finished) or disconnecting from stdin, stderr, stdout and any other file descriptors opened at the time you invoke Popen. If you truly mean that you want a daemon, you should use the python-daemon module, an implementation of PEP 3143. This takes care of the gross parts you don't want to think about.

提交回复
热议问题