title: Reading serial data in realtime in Python
body: <p>I am using a script in Python to collect data from a PIC microcontroller via serial port at 2Mbps.</p>
  
  <p>The PIC works with perfect timing at 2Mbps, also the FTDI usb-serial port works great at 2Mbps (both verified with oscilloscope)</p>
  
  <p>Im sending messages (size of about 15 chars) about 100-150x times a second and the number there increments (to check if i have messages being lost and so on)</p>
  
  <p>On my laptop I have Xubuntu running as virtual machine, I can read the serial port via Putty and via my script (python 2.7 and pySerial)</p>
  
  <p>The problem:</p>
  
  <ul>
  <li>When opening the serial port via Putty I see all messages (the counter in the message increments 1 by 1). Perfect!</li>
  <li>When opening the serial port via pySerial I see all messages but instead of receiving 100-150x per second i receive them at about 5 per second (still the message increments 1 by 1) but they are probably stored in some buffer as when I power off the PIC, i can go to the kitchen and come back and im still receiving messages.</li>
  </ul>
  
  <p>Here is the code (I omitted most part of the code, but the loop is the same):</p>
  
  <pre><code>ser = serial.Serial('/dev/ttyUSB0', 2000000, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False) #Tried with and without the last 3 parameters, and also at 1Mbps, same happens.
  ser.flushInput()
  ser.flushOutput()
  While True:
    data_raw = ser.readline()
    print(data_raw)
  </code></pre>
  
  <p>Anyone knows why pySerial takes so much time to read from the serial port till the end of the line?
  Any help?</p>
  
  <p>I want to have this in real time.</p>
  
  <p>Thank you</p>