Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python script crashes after long time running

I have a python 2.7 script running on a Raspberry Pi 3.

class UIThread(threading.Thread):

   def __init__(self, threadID, name, counter, U):

    threading.Thread.__init__(self)

    self.threadID = threadID

    self.name = name

    self.counter = counter

    self.U = U

  def run(self):

    self.U.run()

def main():

  time.sleep(3)

  try:
     try:
         ###launch a UI running as background thread#####
         U = UIlib.UI()
         thread1 = UIThread(1, "UI", 1, U)
         thread1.daemon = True
         thread1.start()

     except:
         ###if there is no monitor, lanch a fake UI class#######
         U = UIlib.nomonitorUI()
         thread1 = UIThread(1, "NMUI", 1, U)
         thread1.daemon = True
         thread1.start()

         print "No Monitor detected"
         pass

    ####perform interaction with the BQ chip, contain a while true loop######
     char_balan(U)

  except:
    e = sys.exc_info()
    print e
    print "UI exit"

Basely what it does is to send a message through UART to a chip, obtain response message, update log files and print it onto the UI (a UI displayed on monitor created by python curses). It does this every 1 second.

The script has no bug running for 32 hours then it crashes. The UI is crashed and covered with error message:" cannot open shsh: error while loading shared libraries: libc.so.6 : cannot open shared object file..." I have googled this message but didn't find anything related to my python script

I have checked the memory status of the Raspberry Pi. The python process uses about 1/4 of the total memory at the 32th hour. So it is not the memory causing crash. Also, I have tried to run it without a monitor, which will launch a fake UI class without python.curses. same crash happened at the 32th hour.

Now, I am out of idea about why the script crashes.

like image 801
flyblade Avatar asked Dec 15 '16 18:12

flyblade


People also ask

Why does my Python code crash?

A segfaulting program might be the symptom of a bug in C code–or it might be that your process is running out of memory. Crashing is just one symptom of running out of memory.

Can Python run out of memory?

A MemoryError means that the interpreter has run out of memory to allocate to your Python program. This may be due to an issue in the setup of the Python environment or it may be a concern with the code itself loading too much data at the same time.


1 Answers

I have a stack of 8 raspberry pi's working as a seedbox. I had encountered the same error and the nearest official answer that i got from one of my raspi developer friend was that some older kernels have some incompatible bugs with the hardware. Updating to the latest Pixel version would solve your issue.

like image 56
PyManiac Avatar answered Sep 24 '22 06:09

PyManiac