What would be the simplest way to daemonize a python script in Linux?

后端 未结 5 1950
既然无缘
既然无缘 2020-12-14 23:35

What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools.

5条回答
  •  太阳男子
    2020-12-15 00:21

    I have recently used Turkmenbashi :

    $ easy_install turkmenbashi
    import Turkmenbashi
    
    class DebugDaemon (Turkmenbashi.Daemon):
    
        def config(self):
            self.debugging = True
    
        def go(self):
            self.debug('a debug message')
            self.info('an info message')
            self.warn('a warning message')
            self.error('an error message')
            self.critical('a critical message')
    
    if __name__=="__main__":
        d = DebugDaemon()
        d.config()
        d.setenv(30, '/var/run/daemon.pid', '/tmp', None)
        d.start(d.go)
    

提交回复
热议问题