python-daemon: 实现python后台程序的工具

这篇博客介绍了python-daemon库,遵循PEP 3143规范,用于实现Unix系统的守护进程。通过简单的快速入门示例展示了如何启动和停止守护进程,并提供了一个更实用的示例,提醒注意在Python3中可能需要对代码进行调整。
摘要由CSDN通过智能技术生成

简介

python-daemon实现Unix守护进程。 参考: 了解更多

该库实现了PEP 3143“标准守护进程库”的良好行为守护进程规范。

DaemonContext实例保存程序的行为和配置的进程环境。

快速入门

 import time            #  资料学习交流群   QQ 519970686    #

with daemon.DaemonContext():
    f = open("/tmp/test.log",'w')
    while True:
        f.write('''
        Library to implement a well-behaved Unix daemon process.

This library implements the well-behaved daemon specification of PEP 3143, “Standard daemon process library”.

A well-behaved Unix daemon process is tricky to get right, but the required steps are much the same for every daemon program. A DaemonContext instance holds the behaviour and configured process environment for the program; use the instance as a context manager to enter a daemon state.
''')
        f.write("{0}\n".format(time.ctime(time.time())))
      
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值