How do you create a daemon in Python?

后端 未结 16 1708
轻奢々
轻奢々 2020-11-22 01:55

Searching on Google reveals x2 code snippets. The first result is to this code recipe which has a lot of documentation and explanation, along with some useful discussion und

16条回答
  •  梦毁少年i
    2020-11-22 02:37

    Note the python-daemon package which solves a lot of problems behind daemons out of the box.

    Among other features it enables to (from Debian package description):

    • Detach the process into its own process group.
    • Set process environment appropriate for running inside a chroot.
    • Renounce suid and sgid privileges.
    • Close all open file descriptors.
    • Change the working directory, uid, gid, and umask.
    • Set appropriate signal handlers.
    • Open new file descriptors for stdin, stdout, and stderr.
    • Manage a specified PID lock file.
    • Register cleanup functions for at-exit processing.

提交回复
热议问题