Skip to content

Commit c0fc6b8

Browse files
author
Quentin Peter
committed
move code to Kernel
1 parent 188c2a1 commit c0fc6b8

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

ipykernel/kernelapp.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ def init_kernel(self):
433433
"""Create the Kernel object itself"""
434434
shell_stream = ZMQStream(self.shell_socket)
435435
control_stream = ZMQStream(self.control_socket)
436-
stdin_stream = ZMQStream(self.stdin_socket)
437436

438437
kernel_factory = self.kernel_class.instance
439438

@@ -447,18 +446,7 @@ def init_kernel(self):
447446
profile_dir=self.profile_dir,
448447
user_ns=self.user_ns,
449448
)
450-
kernel.stdin_stream = stdin_stream
451449

452-
def handle_msg(msg):
453-
idents, msg = self.session.feed_identities(msg, copy=False)
454-
try:
455-
msg = self.session.deserialize(msg, content=True, copy=False)
456-
except:
457-
self.log.error("Invalid Message", exc_info=True)
458-
return
459-
kernel._stdin_msg = msg
460-
461-
kernel.stdin_stream.on_recv(handle_msg, copy=False)
462450
kernel.record_ports({
463451
name + '_port': port for name, port in self.ports.items()
464452
})

ipykernel/kernelbase.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
from ._version import kernel_protocol_version
4444

45-
4645
CONTROL_PRIORITY = 1
4746
SHELL_PRIORITY = 10
4847
ABORT_PRIORITY = 20
@@ -174,6 +173,18 @@ def __init__(self, **kwargs):
174173

175174
self._stdin_msg = None
176175
self._stdin_lock = threading.Lock()
176+
self.stdin_stream = ZMQStream(self.stdin_socket)
177+
178+
def handle_msg(msg):
179+
idents, msg = self.session.feed_identities(msg, copy=False)
180+
try:
181+
msg = self.session.deserialize(msg, content=True, copy=False)
182+
except Exception:
183+
self.log.error("Invalid Message", exc_info=True)
184+
return
185+
self._stdin_msg = msg
186+
187+
self.stdin_stream.on_recv(handle_msg, copy=False)
177188

178189
@gen.coroutine
179190
def dispatch_control(self, msg):

0 commit comments

Comments
 (0)