From 3fdb0630e04ad454f071510ba186c5e2f7b6a711 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 18 Dec 2020 11:30:57 +0100 Subject: [PATCH] artificially drop iopub messages for testing https://github.com/jupyter/jupyter_client/issues/593 --- ipykernel/iostream.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 4d1e6c95d..476b8eaa6 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -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 #----------------------------------------------------------------------------- @@ -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""" @@ -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