Skip to content

Commit

Permalink
Process control messages before shell messages if no separate control
Browse files Browse the repository at this point in the history
thread
  • Loading branch information
ianthomas23 committed Feb 20, 2024
1 parent fc298e4 commit 991cd08
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,19 @@ async def process_one(self, wait=True):
t, dispatch, args = self.msg_queue.get_nowait()
except (asyncio.QueueEmpty, QueueEmpty):
return

if self.control_thread is None:
# If there isn't a separate control thread then this main thread handles both shell
# and control messages. Before processing a shell message need to flush all control
# messages and allow them all to be processed.
await asyncio.sleep(0)
self.control_stream.flush()

socket = self.control_stream.socket
while socket.poll(1):
await asyncio.sleep(0)
self.control_stream.flush()

await dispatch(*args)

async def dispatch_queue(self):
Expand Down

0 comments on commit 991cd08

Please sign in to comment.