Skip to content

Commit

Permalink
artificially drop iopub messages
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Dec 18, 2020
1 parent a19319e commit 3fdb063
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
MASTER = 0
CHILD = 1

# drop the first this-many iopub messages,
# to mock iopub subscription-propagation delays
IOPUB_DROP_COUNT = 30

#-----------------------------------------------------------------------------
# IO classes
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -69,6 +73,7 @@ def __init__(self, socket, pipe=False):
self._setup_event_pipe()
self.thread = threading.Thread(target=self._thread_main)
self.thread.daemon = True
self.counter = 0

def _thread_main(self):
"""The inner loop that's actually run in a thread"""
Expand Down Expand Up @@ -214,6 +219,11 @@ def send_multipart(self, *args, **kwargs):
def _really_send(self, msg, *args, **kwargs):
"""The callback that actually sends messages"""
mp_mode = self._check_mp_mode()
if self.counter < IOPUB_DROP_COUNT:
sys.__stderr__.write("Not sending %r" % msg)
sys.__stderr__.flush()
self.counter += 1
return

if mp_mode != CHILD:
# we are master, do a regular send
Expand Down

0 comments on commit 3fdb063

Please sign in to comment.