Skip to content

Commit b2bd633

Browse files
author
Quentin Peter
committed
move waiting code to method
1 parent d283077 commit b2bd633

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

ipykernel/kernelbase.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,26 @@ def _input_request(self, prompt, ident, parent, password=False):
878878
content = json_clean(dict(prompt=prompt, password=password))
879879
self.session.send(self.stdin_socket, u'input_request', content, parent,
880880
ident=ident)
881-
882881
# Await a response.
882+
reply = self._wait_input_request_reply()
883+
884+
try:
885+
value = py3compat.unicode_to_str(reply['content']['value'])
886+
except:
887+
self.log.error("Bad input_reply: %s", parent)
888+
value = ''
889+
if value == '\x04':
890+
# EOF
891+
raise EOFError
892+
return value
893+
894+
def _wait_input_request_reply(self):
895+
"""Wait for an input request reply.
896+
897+
Raises
898+
------
899+
KeyboardInterrupt if a keyboard interrupt is recieved.
900+
"""
883901
while True:
884902
try:
885903
ident, reply = self.session.recv(self.stdin_socket, 0)
@@ -890,15 +908,7 @@ def _input_request(self, prompt, ident, parent, password=False):
890908
raise KeyboardInterrupt
891909
else:
892910
break
893-
try:
894-
value = py3compat.unicode_to_str(reply['content']['value'])
895-
except:
896-
self.log.error("Bad input_reply: %s", parent)
897-
value = ''
898-
if value == '\x04':
899-
# EOF
900-
raise EOFError
901-
return value
911+
return reply
902912

903913
def _at_shutdown(self):
904914
"""Actions taken at shutdown by the kernel, called by python's atexit.

0 commit comments

Comments
 (0)