Skip to content

Instantly share code, notes, and snippets.

@tyaslab
Created September 3, 2019 08:12
Show Gist options
  • Save tyaslab/790550bf5ca70bfa5c6ddaae940421fd to your computer and use it in GitHub Desktop.
Save tyaslab/790550bf5ca70bfa5c6ddaae940421fd to your computer and use it in GitHub Desktop.
Daemonize
import time
import logging
from daemonize import Daemonize
pid = "/tmp/test.pid"
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.propagate = False
fh = logging.FileHandler("/tmp/test.log", "w")
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
keep_fds = [fh.stream.fileno()]
def main():
while True:
time.sleep(60)
logger.debug("Test")
daemon = Daemonize(app="test_app", pid=pid, action=main, keep_fds=keep_fds)
daemon.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment