Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:15:42+00:00 2026-06-04T05:15:42+00:00

I have a python daemon built to count the lines of a file once

  • 0

I have a python daemon built to count the lines of a file once every minute, do some math and calculate the number of lines added in the last minute. The output is a basic csv with the count and a timestamp so that I can latter graph it with another script.

The daemon runs for a period of time, “it seems to be between and hour or two”, and then quits. There’s no indication as to why.

The basic daemon template is derived from: This post

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()

Does anyone have any idea why this might be quitting?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:15:43+00:00Added an answer on June 4, 2026 at 5:15 am

    Other than an exception, you have one reason the loop would end and thats this line:

    if not buffer: break
    

    I suggest you log this line before you break and then start tracing it back from there.

    Update
    I was looking at the code a little more closely and overlooked the inner loop. There is nothing that would break the outer loop, so I would guess it must be an exception. A super quick suggestion would be to just wrap your entire loop in a try-except and log anything that occurs:

    try:
        while True:
            ...
    except Exception, e:
        # log e
        raise
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Python nested list that I'm trying to organize and eventually count number
I have a python-based daemon that provides a REST-like interface over HTTP to some
I have a python daemon running as a part of my web app/ How
I have python script which downloads N number of images from website. I run
i have an issue i could use some help with, i have python list
Does Python have a built-in, simple way of encoding/decoding strings using a password? Something
I have some trouble with python. I am trying to get output from a
I have this Python based service daemon which is doing a lot of multiplexed
I have a python script which manages an Erlang daemon. Everything works fine when
I try to write a daemon in python. But I have no idea how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.