linux process stops intermittently

I am learning python programming to use arduino sensors.

My first project is a TMP temp sensor that transmits readings wirelessly to a teensy,
which is connected by USB serial to a headless linux box.

My python code to listen to the serial port and upload data to rrd database is here

#!/usr/bin/python

import serial
from threading import Thread
import time
import rrdtool
import re

def receiving(ser):
    buffer = ''
    while True:
        buffer = ser.read(ser.inWaiting())
        if re.search("Sensor 1:", buffer):
                temperature = buffer[10:15]
                rrdtool.update('TMP36.rrd', 'N:%s' %temperature) # Write values to RRD
        time.sleep(300)    # Time for next read

if __name__ ==  '__main__':
    ser = serial.Serial(
        port="/dev/ttyACM0",
        baudrate=9600,
        bytesize=8,
        parity='N',
        stopbits=1,
        timeout=0.1,
        xonxoff=0,
        rtscts=0,
        interCharTimeout=None
    )

    Thread(target=receiving, args=(ser,)).start()

I started the script with this
$ nohup python ./new_thread_read.py &

It ran for a few days and then it stopped in the middle of the night. Nothing in the logs to explain
what happened.

I'm not a programmer but would like to know how to keep the python script running.
Writing a cron script to check if the process stopped and then restart it seems unwieldy.

Is there something in the Python code that makes it vulnerable to serial data hiccups?

I'm learning Python and your code seem very complicated for a simple problem. Why do you need a Thread ?

I don't claim that my Python code is elegant - but I think it works. Look at this demo.

...R

I am running this python code 24/7 on a small ARM SoC system and I am trying to minimize resource use. Granted, the threading may not save much but it may help reduce the chance of the system crashing.

After some web searching I came upon a solution. Run a cron job regularly to check if the python process is running- if not then start it. On my server, the services_check script runs hourly.

bad_gui:
I am running this python code 24/7 on a small ARM SoC system and I am trying to minimize resource use. Granted, the threading may not save much but it may help reduce the chance of the system crashing.

Your own evidence does not seem to support this

It ran for a few days and then it stopped in the middle of the night.

...R

Your own evidence does not seem to support this

It crashes less often with the threading code. I don't claim that it will never crash.