title: Read and write to UART pyserial using timeout functionality
body: <p>I have written a UART py-serial script, which looks like.</p>
  <pre><code>import serial
  import time
  
  try:
       ser = serial.Serial(
       #port='/dev/ttyAMA0',
       port='/dev/ttyUSB1',
       baudrate = 9600,
       parity=serial.PARITY_NONE,
       stopbits=serial.STOPBITS_ONE,
       bytesize=serial.EIGHTBITS,
       timeout=2
      )
      print ('Connection is open : ',str(ser.isOpen()))
  except Exception as e:
      print (&quot;Something got wrong: &quot;, e)
  
  
  ser.write(b'hello..')
  </code></pre>
  <p>and have a similar script as receiver.</p>
  <p>what I want is:
  suppose timeout = 5</p>
  <pre><code>ser.write(b'Helloo...')
  ser.flush()
  ser.readline()
  </code></pre>
  <p>the other script is reading it and sending a response via serial only.
  this readline should wait maximum for this timeout, if it received response in 2 seconds then it should not wait for 5seconds.</p>
  <p>But using this timeout it waits for 2 seconds, even if the data is received in a second.</p>
  <h1>so my concern is to wait maximum for timeout, but if data received earlier it should end and proceed.</h1>
  <p>Not able to find this functionality, please help.</p>