From 730a812c5228cadf9e4e5b84d4396544065146cd Mon Sep 17 00:00:00 2001 From: Jack Amadeo Date: Mon, 21 Mar 2022 22:17:23 -0400 Subject: [PATCH] Check if the current thread is the io thread --- ipykernel/iostream.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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.