How do you create a daemon in Python?

后端 未结 16 1885
轻奢々
轻奢々 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 02:50

    Though you may prefer the pure Python solution provided by the python-daemon module, there is a daemon(3) function in libc -- at least, on BSD and Linux -- which will do the right thing.

    Calling it from python is easy:

    import ctypes
    
    ctypes.CDLL(None).daemon(0, 0) # Read the man-page for the arguments' meanings
    

    The only remaining thing to do is creation (and locking) of the PID-file. But that you can handle yourself...

提交回复
热议问题