Skip to content

Commit 991cd08

Browse files
committed
Process control messages before shell messages if no separate control
thread
1 parent fc298e4 commit 991cd08

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ipykernel/kernelbase.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ async def process_one(self, wait=True):
492492
t, dispatch, args = self.msg_queue.get_nowait()
493493
except (asyncio.QueueEmpty, QueueEmpty):
494494
return
495+
496+
if self.control_thread is None:
497+
# If there isn't a separate control thread then this main thread handles both shell
498+
# and control messages. Before processing a shell message need to flush all control
499+
# messages and allow them all to be processed.
500+
await asyncio.sleep(0)
501+
self.control_stream.flush()
502+
503+
socket = self.control_stream.socket
504+
while socket.poll(1):
505+
await asyncio.sleep(0)
506+
self.control_stream.flush()
507+
495508
await dispatch(*args)
496509

497510
async def dispatch_queue(self):

0 commit comments

Comments
 (0)