diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index a6451bebb..56fea46c2 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -257,14 +257,14 @@ async def _flush_control_queue(self): control_loop = self.io_loop tracer_future = awaitable_future = asyncio.Future() - def _flush(): + async def _flush(): # control_stream.flush puts messages on the queue self.control_stream.flush() # put Future on the queue after all of those, # so we can wait for all queued messages to be processed - self.control_queue.put(tracer_future) + await self.control_queue.put(tracer_future) - control_loop.call_soon_threadsafe(_flush) + asyncio.run_coroutine_threadsafe(_flush(), control_loop) return awaitable_future async def process_control(self, msg):