pexpect : Is there any way to prevent input overrun while using pexpect?
<p>Using pexpect, I am connecting to a linux machine console which is a machine with limited capabilities.
When I spawn a connection and try to execute command using send or sendline I get error saying <code>"ttyAMA0: 1 input overrun(s)"</code></p>

<p>This is probably happening because <code>pexpect</code> sending input to console very fast before it is consumed and leading to input buffer overrun. 
If in some way <code>pexpect</code> slows down the speed of input to console, then it will prevent from input buffer overrun.  Is there any parameter which defines character rate for input to console? </p>

<p>For similar problem, tcl-expect has command send_slow which slows down input rate to provided value. Would be happy to have any equivalent to <code>send_slow</code> in python-expect. </p>

<p>Also tried setting window size in expect and still there's no change in the error.
Also the error I'm getting is intermittent. </p>

<p>Disclaimer: This is a workaround than actual solution to buffer overrun problem. 
Did following steps:</p>

<ol>
<li>Before calling python script having pexpect, set baud rate to match with the console/telnet connect using stty. E.g. <code>stty speed 50</code></li>
<li>Spawn new shell in pexpect and set <code>delaybeforesend</code> and <code>delayaftersend</code> to desired value (only required when your devide is being too slow)</li>
<li>Replace sendline with our own custom sendline_slow which will send 1 character at a time. </li>
</ol>

<p>def sendline_slow(spawn_id, cmd):</p>

<pre><code>   for char  in str(cmd):
      spawn_id.send(char)
   spawn_id.send('\n')
</code></pre>

<p>Bingo. Now I am able to send commands in super slow fashion to console...!</p>

python linux expect tty pexpect