Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
flush stale messages on stdin channel prior to raw_input
  • Loading branch information
minrk committed Apr 25, 2013
commit 8b1382ede6927808e31f258037daad17391eacc3
11 changes: 10 additions & 1 deletion IPython/kernel/zmq/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,16 @@ def _raw_input(self, prompt, ident, parent):
# Flush output before making the request.
sys.stderr.flush()
sys.stdout.flush()

# flush the stdin socket, to purge stale replies
while True:
try:
self.stdin_socket.recv_multipart(zmq.NOBLOCK)
except zmq.ZMQError as e:
if e.errno == zmq.EAGAIN:
break
else:
raise

# Send the input request.
content = json_clean(dict(prompt=prompt))
self.session.send(self.stdin_socket, u'input_request', content, parent,
Expand Down