我想使用pip包python守护进程来守护我的一个任务,但是即使用我能想到的最简单的例子,我也无法让它运行。在
下面的代码片段显示“Hallo”并记录“Before with语句”,但不执行任何其他操作。在
守护进程的pid文件将被创建和删除,并且如果您放入一些时间。睡觉()在里面,但它什么也没记录。 “After with..”也从未出现在日志中。在
有人能指出我做错了什么吗?在
提前谢谢。在
#!/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")
目前没有回答
相关问题 更多 >
编程相关推荐