python runner.daemonrunner_Python3创建守护进程

嗨,我尝试在

python中创建一个守护进程,以便在Ubuntu服务器上运行.下面的代码是我遇到问题的代码.

import sys

import time

import threading

import logging

import logging.handlers

from daemon import runner

class Main(object):

def run(self):

my_logger = logging.getLogger('NameGeneratorDeamon')

my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler(address=('192.168.0.69', 514),facility=LOG_DAEMON)

my_logger.addHandler(handler)

try:

my_logger.info('Started')

while True:

pass

except Exception as inst:

#Send error to syslog server

my_logger.critical(inst)

class App():

def __init__(self):

self.stdin_path = '/dev/null'

self.stdout_path = '/dev/null'

self.stderr_path = '/dev/null'

self.pidfile_path = '/tmp/foo.pid'

self.pidfile_timeout = 5

def run(self):

service = Main()

service.run()

app = App()

daemon_runner = runner.DaemonRunner(app)

daemon_runner.do_action()

我运行代码时收到的错误消息如下:

File "Main.py", line 35, in

daemon_runner = runner.DaemonRunner(app)

File "/usr/local/lib/python3.4/dist-packages/daemon/runner.py", line 111, in __init__

self.daemon_context.stdout = open(app.stdout_path, 'w+t')

io.UnsupportedOperation: File or stream is not seekable.

有谁知道如何解决这个问题,或者你有更好的方法在Python中创建一个守护进程?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值