Python 3.3.4:python-daemon-3K;如何使用跑步者 [英] Python 3.3.4: python-daemon-3K ; How to use runner

查看:199
本文介绍了Python 3.3.4:python-daemon-3K;如何使用跑步者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用Python 3.3.4使python守护程序正常工作。我正在使用PyPi的最新版本的python-daemon-3K,即1.5.8

Struggling to try and get a python daemon to work using Python 3.3.4. Im using the latest version of the python-daemon-3K from PyPi i.e. 1.5.8

起点是找到以下代码如何使用Python创建守护程序?我认为是2.x Python的代码。

Starting point is the following code found How do you create a daemon in Python? code i believe is 2.x Python.

import time
from daemon import runner

class App():
    def __init__(self):
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/tty'
        self.stderr_path = '/dev/tty'
        self.pidfile_path =  '/tmp/foo.pid'
        self.pidfile_timeout = 5
    def run(self):
        while True:
            print("Howdy!  Gig'em!  Whoop!")
            time.sleep(10)

app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()

尝试运行此命令会出现以下错误。

Attempting to run this i get the following error.


python mydaemon.py start

追溯(最近一次通话最近):
文件 mydaemon.py,第60行,在
中daemon_runner = Runner.DaemonRunner(app)
init
app.stderr_path,'w +',缓冲= 0)
ValueError:不能有未缓冲的文本I / O

python mydaemon.py start
Traceback (most recent call last): File "mydaemon.py", line 60, in daemon_runner = runner.DaemonRunner(app) File "/depot/Python-3.3.4/lib/python3.3/site-packages/python_daemon_3K-1.5.8-py3.3.egg/daemon/runner.py", line 89, in init app.stderr_path, 'w+', buffering=0) ValueError: can't have unbuffered text I/O

任何指针如何翻译以与Python 3.3.4配合使用,或者是在python-daemon-3K中使用运行器的一个很好的例子

Any pointer how to translate to work with Python 3.3.4 or a good example of using the runner in python-daemon-3K

感谢
derek

Thanks derek

推荐答案

要使代码在python3中运行,您需要在 DaemonRunner中进行更改类,您不能具有未缓冲的文本IO,但是可以具有未缓冲的字节IO,因此将模式更改为'wb +'将起作用:

To make the code run in python3 you need to make a change in the DaemonRunner class, you cannot have unbuffered text IO but you can have unbuffered bytes IO so changing the mode to'wb+' will work:

class DaemonRunner(object):

        self.parse_args()
        self.app = app
        self.daemon_context = DaemonContext()
        self.daemon_context.stdin = open(app.stdin_path, 'r') 
        # for linux /dev/tty must be opened without buffering and with b
        self.daemon_context.stdout = open(app.stdout_path, 'wb+',buffering=0)
        # w+ -> wb+
        self.daemon_context.stderr = open(
            app.stderr_path, 'wb+', buffering=0)

这篇关于Python 3.3.4:python-daemon-3K;如何使用跑步者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆