Skip to content

Commit 188c2a1

Browse files
author
Quentin Peter
committed
add lock to stdin
1 parent 55f44a1 commit 188c2a1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

ipykernel/kernelapp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ def init_kernel(self):
448448
user_ns=self.user_ns,
449449
)
450450
kernel.stdin_stream = stdin_stream
451-
kernel._stdin_msg = None
452451

453452
def handle_msg(msg):
454453
idents, msg = self.session.feed_identities(msg, copy=False)

ipykernel/kernelbase.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def __init__(self, **kwargs):
172172
for msg_type in self.control_msg_types:
173173
self.control_handlers[msg_type] = getattr(self, msg_type)
174174

175+
self._stdin_msg = None
176+
self._stdin_lock = threading.Lock()
177+
175178
@gen.coroutine
176179
def dispatch_control(self, msg):
177180
"""dispatch control requests"""
@@ -876,13 +879,14 @@ def _input_request(self, prompt, ident, parent, password=False):
876879
else:
877880
raise
878881

879-
self._stdin_msg = None
880-
# Send the input request.
881-
content = json_clean(dict(prompt=prompt, password=password))
882-
self.session.send(self.stdin_socket, u'input_request', content, parent,
883-
ident=ident)
884-
# Await a response.
885-
reply = self._wait_input_request_reply()
882+
with self._stdin_lock:
883+
self._stdin_msg = None
884+
# Send the input request.
885+
content = json_clean(dict(prompt=prompt, password=password))
886+
self.session.send(self.stdin_socket, u'input_request', content, parent,
887+
ident=ident)
888+
# Await a response.
889+
reply = self._wait_input_request_reply()
886890

887891
try:
888892
value = py3compat.unicode_to_str(reply['content']['value'])

0 commit comments

Comments
 (0)