diff --git a/ipykernel/control.py b/ipykernel/control.py index 57a7ac727..7ac56b7f9 100644 --- a/ipykernel/control.py +++ b/ipykernel/control.py @@ -9,7 +9,7 @@ class ControlThread(Thread): - def __init__(self, log=None, **kwargs): + def __init__(self, **kwargs): Thread.__init__(self, **kwargs) self.io_loop = IOLoop(make_current=False) self.pydev_do_not_trace = True diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index 090e62e05..7bf4a54ba 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -301,7 +301,8 @@ def init_control(self, context): self.debug_shell_socket = context.socket(zmq.DEALER) self.debug_shell_socket.linger = 1000 - self.debug_shell_socket.connect(self.shell_socket.getsockopt(zmq.LAST_ENDPOINT)) + if self.shell_socket.getsockopt(zmq.LAST_ENDPOINT): + self.debug_shell_socket.connect(self.shell_socket.getsockopt(zmq.LAST_ENDPOINT)) if hasattr(zmq, 'ROUTER_HANDOVER'): # set router-handover to workaround zeromq reconnect problems @@ -345,7 +346,10 @@ def close(self): self.iopub_thread.stop() self.iopub_thread.close() - self.debug_shell_socket.close() + if self.debugpy_socket and not self.debugpy_socket.closed: + self.debugpy_socket.close() + if self.debug_shell_socket and not self.debug_shell_socket.closed: + self.debug_shell_socket.close() for channel in ('shell', 'control', 'stdin'): self.log.debug("Closing %s channel", channel) diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index 0643fcd7b..7b2917d23 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -187,8 +187,8 @@ def __init__(self, **kwargs): self.session) self.control_queue = Queue() - kwargs['control_thread'].io_loop.add_callback(self.poll_control_queue) - + if 'control_thread' in kwargs: + kwargs['control_thread'].io_loop.add_callback(self.poll_control_queue) @gen.coroutine def dispatch_debugpy(self, msg):