diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 50f86d243..a1a54a84e 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -455,7 +455,12 @@ def flush(self): send will happen in the background thread """ - if self.pub_thread and self.pub_thread.thread is not None and self.pub_thread.thread.is_alive(): + if ( + self.pub_thread + and self.pub_thread.thread is not None + and self.pub_thread.thread.is_alive() + and self.pub_thread.thread.ident != threading.current_thread().ident + ): # request flush on the background thread self.pub_thread.schedule(self._flush) # wait for flush to actually get through, if we can.