Skip to content

Commit a7b8a9a

Browse files
committed
publish IOPub from a background thread
removes need to call `sys.stdout.flush` during blocking loops for backward-compatibility, a BackgroundSocket is passed around that transparently sends messages via the IOPub thread.
1 parent 950472c commit a7b8a9a

File tree

5 files changed

+221
-128
lines changed

5 files changed

+221
-128
lines changed

ipykernel/inprocess/iostream.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""inprocess OutStream subclass"""
2+
3+
# Copyright (c) IPython Development Team.
4+
# Distributed under the terms of the Modified BSD License.
5+
6+
from .. import iostream
7+
8+
class OutStream(iostream.OutStream):
9+
def __init__(self, session, pub_thread, name, pipe=False):
10+
pub_thread.io_loop = None
11+
super(OutStream, self).__init__(session, pub_thread, name)
12+
13+
def _schedule_flush(self):
14+
self.flush()
15+
16+
def flush(self):
17+
self._flush()

ipykernel/inprocess/ipkernel.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ipykernel.zmqshell import ZMQInteractiveShell
1515

1616
from .socket import DummySocket
17+
from .iostream import OutStream
1718

1819
#-----------------------------------------------------------------------------
1920
# Main kernel class
@@ -128,12 +129,10 @@ def _shell_class_default(self):
128129
return InProcessInteractiveShell
129130

130131
def _stdout_default(self):
131-
from ipykernel.iostream import OutStream
132-
return OutStream(self.session, self.iopub_socket, u'stdout', pipe=False)
132+
return OutStream(self.session, self.iopub_socket, u'stdout')
133133

134134
def _stderr_default(self):
135-
from ipykernel.iostream import OutStream
136-
return OutStream(self.session, self.iopub_socket, u'stderr', pipe=False)
135+
return OutStream(self.session, self.iopub_socket, u'stderr')
137136

138137
#-----------------------------------------------------------------------------
139138
# Interactive shell subclass

0 commit comments

Comments
 (0)