title: Arduino to Python serial connection gets clogged
body: <p>I have code that works fine for about 15 minutes and then without any indication why creates a problem.</p>
  <p>The setup:
  An Arduino Nano sends a value via serial to a python script (Python 3.9.13), which then prints the value to the terminal. Python runs on a Linux machine.</p>
  <p>Upon first startup, the printed value is the same value for about 2-5 seconds, then it prints the correct values. The system works fine for about 15 minutes and then &quot;freezes&quot; meaning that it simply prints the same value forever. When I abort (crtl+c) and restart the python script, I get correct values again.</p>
  <p>This is the python code I am using (including only the relevant parts):</p>
  <pre><code>port = '/dev/ttyUSB0'
  baudrate = 19200
  
  def read_arduino(arduino):
      my_boolean = False
      while True:
          try:
              interesting_value = arduino.readline()
              decoded = float(interesting_value[0:len(interesting_value)-2].decode())
          except OSError as e:
              print('OS Error occured')
          except UnicodeDecodeError as e:
              print('Unicode Error occured')
          except ValueError as e:
              print('Value Error occured')
          else:
              if (decoded &gt; THRESHOLD) &amp; (not my_boolean):
                  my_boolean = True
                  # Debug prints               
                  # print('TRUE')
                  # print(f'\n {decoded}\n')
                  msg = struct.pack(&quot;&lt;d&quot;,0)
                  socket.sendto(msg,(host_AP,port_AP))
              elif (decoded &lt; THRESHOLD) &amp; my_boolean:
                  my_boolean = False
                  # Debug prints
                  # print('FALSE')
                  # print(f'\n {decoded}\n')
                  msg = struct.pack(&quot;&lt;d&quot;,1)
                  socket.sendto(msg,(host_AP,port_AP))
  
  with serial.Serial(port, baudrate, timeout=1) as arduino:
  
      # read the arduino values
      read_arduino(arduino)
  </code></pre>
  <p>Again, the system works, until it just goes into this frozen state of sending/reading the same value over and over. Normally the values fluctuate between 800 and 900 and are NEVER the same. To there is clearly some issue, but we cannot reproduce it, except by waiting for a long time and then seeing the same value printed indefinitely.</p>
  <p>Thanks in advance for any ideas/help!</p>