7

Python 3.3.4 を使用して Python デーモンを動作させるのに苦労しています。PyPi ie 1.5.8 の python-daemon-3K の最新バージョンを使用しています

出発点は、次のコードが見つかりました。 Python でデーモンを作成するにはどうすればよいですか? コードは 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()

これを実行しようとすると、次のエラーが発生します。

python mydaemon.py start
トレースバック (最新の呼び出しが最後): ファイル "mydaemon.py"、60 行目、daemon_runner = runner.DaemonRunner(app) ファイル "/depot/Python-3.3.4/lib/python3.3/site -packages/python_daemon_3K-1.5.8-py3.3.egg/daemon/runner.py", line 89, init app.stderr_path, 'w+', buffering=0) ValueError: バッファリングされていないテキスト I/O を持つことはできません

Python 3.3.4 で動作するように変換する方法のポインタ、または python-daemon-3K でランナーを使用する良い例

ありがとうデレク

4

2 に答える 2

5

コードを python3 で実行するには、DaemonRunnerクラスを変更する必要があります。バッファリングされていないテキスト IO を持つことはできませんが、バッファリングされていないバイト IO を持つことはできるため、モードを次のように変更する'wb+'と機能します。

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)
于 2015-09-16T10:56:07.477 に答える
0

コードを python3 で実行するには、DaemonRunnerクラスを変更する必要があります

class DaemonRunner(object):
    self.parse_args()
    self.app = app
    self.daemon_context = DaemonContext()
    self.daemon_context.stdin = open(app.stdin_path, 'r') 
    self.daemon_context.stdout = open(app.stdout_path, 'w+')
    self.daemon_context.stderr = open(app.stderr_path, 'w+')
于 2016-11-16T09:43:29.503 に答える