私は、ファイルの行を毎分1回カウントし、いくつかの計算を行い、最後の1分間に追加された行数を計算するように構築されたpythonデーモンを持っています。出力は、カウントとタイムスタンプを含む基本的な csv であるため、後で別のスクリプトでグラフ化できます。
デーモンは一定時間実行され、「1 ~ 1 時間か 2 時間のようです」と終了します。理由については示されていません。
基本的なデーモン テンプレートは、次の記事から派生しています。
import os
import subprocess
import time
from daemon import runner
import datetime
inputfilename="test_data"
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/counter.pid'
self.pidfile_timeout = 5
def run(self):
counter1 = 0
counter_log = 0
while True:
count = 0
output = open("tpm_counter.log", 'a')
FILEIN = open(inputfilename, 'rb')
while 1:
buffer = FILEIN.read(8192*1024)
if not buffer: break
count += buffer.count('\n')
FILEIN.close( )
counter_log = (count - counter1) * 30
now = str(datetime.datetime.now())
counter1 = count
line = str(counter_log)
output.write(line)
output.write(", ")
output.write(now)
output.write("\n")
output.close( )
# set the sleep time for repeated action here:
time.sleep(60)
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
なぜこれが終了するのか、誰にも分かりますか?