Python pythondaemondaemonize 09/10/2016

Example on using daemonize module in Python

Install:

pip install daemonize

Example:

#!/usr/bin/env python3

import os
import sys
import time
from daemonize import Daemonize

def main():
    while True:
        time.sleep(10)

if __name__ == '__main__':
    appname=os.path.basename(sys.argv[0])
    pidfile='/tmp/mypidfile.pid'
    daemon = Daemonize(app=appname,pid=pidfile, action=main)
    daemon.start()