1

I want to use the pip package python-daemon to daemonize one of my tasks, but I can't get it to run even with the most simple example I can think of.

The following code snipplet displays "Hallo" und logs the "Before with statement", but doesn't do anything else.

The pid-File for the daemon will be created and deleted and the job lasts longer if you put in some time.sleep() inside, but it doesn't log anything. The "After with.." also never shows up in the log.

Can someone point out what I'm doing wrong here?

Thanks in advance.

#!/usr/bin/python3

# pip3 install python-daemon
import daemon
import lockfile
import logging


LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename="/tmp/test.log",
                    level=logging.DEBUG,
                    format=LOG_FORMAT)
logger = logging.getLogger()

context = daemon.DaemonContext(working_directory='/tmp/',
                               pidfile=lockfile.FileLock('/tmp   /test.pid'),
                               )

logger.info("Before with statement")
print("Hallo")

with context:
    logger.info("Info")

logger.info("After with statement")
4

0 回答 0