title: pySerial reading data is delayed
body: <p>I am reading serial data from an esp32 with <a href="https://pyserial.readthedocs.io/en/latest/pyserial.html" rel="nofollow noreferrer">pySerial</a>. The esp32 is sending the data quite fast (~every 10ms). If I try to read out the data with pyserial, i takes really long.</p>
  <p>Without a specified timeout for pySerial class, it takes around 3s to read out my command string and I dont know what it is waiting for. Furthermore, because of the 3s, the buffer is getting bigger and bigger.</p>
  <p>With a timeout and with reducing the sending frequency of the esp32 to 200ms, it works.  But if i use a too small timeout it won't read out my whole command string I send with the esp32. And i have to adjust the timeout to the sending frequency of the esp.</p>
  <p>What irritates me, is that the 'read_until()' method is taking 3s to read until my seperator char. But if the method stops earlier because of the timeout, it already fetched the whole serial data string.</p>
  <pre><code>class USBReader:
      def __init__(self) -&gt; None:
          self.readerThread = Thread(target=self.read_usb)
          self.ser = serial.Serial(port='COM3', baudrate=500000, timeout=0.3)
  
      def read_usb(self):
          while True:
              start = datetime.datetime.now()
              self.ser.flushOutput()
              try:
                  start = datetime.datetime.now()
                  command_ = self.ser.read_until(b';').decode(&quot;UTF-8&quot;)
                  end = datetime.datetime.now()
                  command = command_.replace(&quot;\n&quot;, &quot;&quot;).replace(&quot;\r&quot;, &quot;&quot;)
                  print(command)
                  print(end - start)
              except UnicodeDecodeError:
                  print(&quot;error&quot;)
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>I found out the problem was with my two <a href="https://docs.python.org/3/library/threading.html" rel="nofollow noreferrer">Threads</a> i used. One Thread is for reading the data and the second one is for processing it. The processing was done inside a while loop, which was using all the RAM?. I inserted a sleep of 0.01s and everythings works fine</p>