2016-05-30 9 views
4

こんにちは私は、デーモンをPythonで作成して、Ubuntu Server上で実行しようとしています。以下のコードは問題があるコードです。Python3デーモンを作成する

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 <module> 
    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

'Python3 main.py start'コマンドを実行します。 –

+0

'/dev/null'がシーク可能でないという事実と関係がありますか? – Tico

答えて

0

私の場合:

# vi /usr/local/lib/python3.5/dist-packages/daemon/runner.py 
# 118 -120 
     self.daemon_context = DaemonContext() 
     self.daemon_context.stdin = open(app.stdin_path, 'wb+',buffering=0) 
     self.daemon_context.stdout = open(app.stdout_path, 'wb+',buffering=0) 
     self.daemon_context.stderr = open(
       app.stderr_path, 'wb+', buffering=0) 

その後、エラーなし!

+0

コードのみの回答は、StackOverflowでは推奨されません。これが正解である理由について少し詳しく説明してください – Mittal

関連する問題