Skip to content

Commit

Permalink
Forward ioPub to frontend when the kernel is idle #234
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Jul 17, 2019
1 parent dba774b commit 9599210
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sos_notebook/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fnmatch
import logging
import os
import threading
import subprocess
import sys
import time
Expand Down Expand Up @@ -727,6 +728,7 @@ def __init__(self, **kwargs):
env.logger.print = lambda cell_id, msg, *args: \
self.send_frontend_msg('print', [cell_id, msg])
self.controller = None
self._kernel_busy = threading.Event()

cell_id = property(lambda self: self._meta['cell_id'])
_workflow_mode = property(lambda self: self._meta['workflow_mode'])
Expand Down Expand Up @@ -1164,6 +1166,7 @@ def warn(self, message):
})

def run_cell(self, code, silent, store_history, on_error=None):
self._kernel_busy.set()
#
if not self.KM.is_alive():
self.send_response(
Expand Down Expand Up @@ -1260,6 +1263,7 @@ def run_cell(self, code, silent, store_history, on_error=None):
res = reply['content']
shell_ended = True
time.sleep(0.001)
self._kernel_busy.clear()
return res

def switch_kernel(self,
Expand Down Expand Up @@ -1647,6 +1651,16 @@ def init_metadata(self, metadata):
self.comm_manager.register_target('sos_comm', self.sos_comm)
return self._meta

def kernel_idle_func(self):
''' forward ioPub messages from subkernels to frontend '''
# self._kernel_busy needs to be a signal because `kernel_idle_func` will be called
# in a thread (controller)
if self._kernel_busy.is_set():
return
for _, kc in self.kernels.values():
while kc.iopub_channel.msg_ready():
self.session.send(self.iopub_socket, kc.iopub_channel.get_msg())

def do_execute(self,
code,
silent,
Expand Down

0 comments on commit 9599210

Please sign in to comment.