diff --git a/ipykernel/inprocess/ipkernel.py b/ipykernel/inprocess/ipkernel.py index bc17236d6..515fc06ac 100644 --- a/ipykernel/inprocess/ipkernel.py +++ b/ipykernel/inprocess/ipkernel.py @@ -57,7 +57,6 @@ class InProcessKernel(IPythonKernel): @default('iopub_thread') def _default_iopub_thread(self): thread = IOPubThread(self._underlying_iopub_socket) - thread.start() return thread iopub_socket = Instance(BackgroundSocket) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 1463a9eca..221c036eb 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -45,7 +45,7 @@ class IOPubThread: """ def __init__(self, socket, pipe=False): - """Create IOPub thread + """Create IOPub thread and start it Parameters ---------- @@ -73,6 +73,9 @@ def __init__(self, socket, pipe=False): self._events = deque() self._event_pipes = WeakSet() self._setup_event_pipe() + # make sure we don't prevent process exit + # I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be. + atexit.register(self.stop) def _thread_main(self): """The inner loop that's actually run in a thread""" @@ -177,14 +180,6 @@ def _check_mp_mode(self): else: return CHILD - def start(self): - """Start the IOPub thread""" - self.thread.name = "IOPub" - self.thread.start() - # make sure we don't prevent process exit - # I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be. - atexit.register(self.stop) - def stop(self): """Stop the IOPub thread""" if not self.thread.is_alive(): @@ -369,7 +364,6 @@ def __init__( stacklevel=2, ) pub_thread = IOPubThread(pub_thread) - pub_thread.start() self.pub_thread = pub_thread self.name = name self.topic = b"stream." + name.encode() diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index 3b8092f48..7411ac36c 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -282,7 +282,7 @@ def set_sigint_result(): if sigint_future.cancelled() or sigint_future.done(): return sigint_future.set_result(1) - # use call_soon_threadsage for thread safety + # use call_soon_threadsafe for thread safety self.io_loop.call_soon_threadsafe(set_sigint_result) # set the custom sigint hander during this context diff --git a/ipykernel/tests/test_io.py b/ipykernel/tests/test_io.py index cad617879..616871417 100644 --- a/ipykernel/tests/test_io.py +++ b/ipykernel/tests/test_io.py @@ -16,7 +16,6 @@ def test_io_api(): ctx = zmq.Context() pub = ctx.socket(zmq.PUB) thread = IOPubThread(pub) - thread.start() stream = OutStream(session, thread, 'stdout') @@ -47,7 +46,6 @@ def test_io_isatty(): ctx = zmq.Context() pub = ctx.socket(zmq.PUB) thread = IOPubThread(pub) - thread.start() stream = OutStream(session, thread, 'stdout', isatty=True) assert stream.isatty()