Skip to content

Commit f516a39

Browse files
committed
Start IOPubThread at creation
1 parent a32a71c commit f516a39

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

ipykernel/inprocess/ipkernel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class InProcessKernel(IPythonKernel):
5757
@default('iopub_thread')
5858
def _default_iopub_thread(self):
5959
thread = IOPubThread(self._underlying_iopub_socket)
60-
thread.start()
6160
return thread
6261

6362
iopub_socket = Instance(BackgroundSocket)

ipykernel/iostream.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class IOPubThread:
4545
"""
4646

4747
def __init__(self, socket, pipe=False):
48-
"""Create IOPub thread
48+
"""Create IOPub thread and start it
4949
5050
Parameters
5151
----------
@@ -73,6 +73,9 @@ def __init__(self, socket, pipe=False):
7373
self._events = deque()
7474
self._event_pipes = WeakSet()
7575
self._setup_event_pipe()
76+
# make sure we don't prevent process exit
77+
# I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be.
78+
atexit.register(self.stop)
7679

7780
def _thread_main(self):
7881
"""The inner loop that's actually run in a thread"""
@@ -177,14 +180,6 @@ def _check_mp_mode(self):
177180
else:
178181
return CHILD
179182

180-
def start(self):
181-
"""Start the IOPub thread"""
182-
self.thread.name = "IOPub"
183-
self.thread.start()
184-
# make sure we don't prevent process exit
185-
# I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be.
186-
atexit.register(self.stop)
187-
188183
def stop(self):
189184
"""Stop the IOPub thread"""
190185
if not self.thread.is_alive():
@@ -369,7 +364,6 @@ def __init__(
369364
stacklevel=2,
370365
)
371366
pub_thread = IOPubThread(pub_thread)
372-
pub_thread.start()
373367
self.pub_thread = pub_thread
374368
self.name = name
375369
self.topic = b"stream." + name.encode()

ipykernel/ipkernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def set_sigint_result():
282282
if sigint_future.cancelled() or sigint_future.done():
283283
return
284284
sigint_future.set_result(1)
285-
# use call_soon_threadsage for thread safety
285+
# use call_soon_threadsafe for thread safety
286286
self.io_loop.call_soon_threadsafe(set_sigint_result)
287287

288288
# set the custom sigint hander during this context

ipykernel/tests/test_io.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_io_api():
1616
ctx = zmq.Context()
1717
pub = ctx.socket(zmq.PUB)
1818
thread = IOPubThread(pub)
19-
thread.start()
2019

2120
stream = OutStream(session, thread, 'stdout')
2221

@@ -47,7 +46,6 @@ def test_io_isatty():
4746
ctx = zmq.Context()
4847
pub = ctx.socket(zmq.PUB)
4948
thread = IOPubThread(pub)
50-
thread.start()
5149

5250
stream = OutStream(session, thread, 'stdout', isatty=True)
5351
assert stream.isatty()

0 commit comments

Comments
 (0)