Python streams with long timers exiting unexpectedly

I am working on a python program that runs as a daemon and creates several different long threads with potentially separate sleep timers.

The problem I'm running into is that threads die after an unknown amount of time and I'm not entirely sure why or how to diagnose the problems. I went and added (albeit not a definitive solution) a function __del__

to make the class execute as a thread to see what the problem might be, but I'm not sure what variables are available to determine what is causing the exit.

I am no closer to identifying the cause of the problem and hope to find some help.

A snippet of my main launcher, which is a top-level daemon process:

threads = []
sensorFolders = glob.glob(config._baseDir + '28*')
for folder in sensorFolders:
    sensorID = os.path.split(folder)[1]
    sensor = Sensor().getSensor(sensorID)
    threads.append(threading.Thread(target=sensor.startCheckin))
for thread in threads:
    thread.start()
for thread in threads:
    thread.join()

      

And a piece of the sensor class:

def startCheckin(self):
    while True:
        self.checkSensor()
        self.checkinSensor()
        self.postTemp()
        time.sleep(self._checkinInterval)

      

I can of course add more code as needed, but it's pretty simple to implement. I'm just not sure what to try here as there isn't (for a python noob) to be something obvious that could cause threads to close abruptly.

Any help would be greatly appreciated!

Edit The problem is that if the network goes down for a moment and the thread makes a url request, it doesn't know where to find the host and throws an exception. Unfortunately, knowing this, I still don't know how best to deal with these exceptions.

+3


source to share


1 answer


So, I only see 3 possibilities:

  • The thread is throwing an exception and you don't look or notice stderr
  • Something called by a thread calls sys.exit, this will force that thread to stop.
  • If any blocking or blocking operations are in use, it is possible that the thread is blocking itself or blocking indefinitely on some io operation.

in either of these cases, by adding a thread dumping lock like this:



fooobar.com/questions/2580 / ...

should show you what's going on in that thread (or if it's gone).

0


source







All Articles