def __init__(self, manager, info, name=""): self._manager = manager # Store info that defines the kernel self._originalInfo = KernelInfo(info) # Make a copy for the current version. This copy is re-created on # each restart self._info = ssdf.copy(self._originalInfo) # Store name (or should the name be defined in the info struct) self._name = name # Create context for the connection to the kernel and IDE's # This context is persistent (it stays as long as this KernelBroker # instance is alive). self._context = yoton.Context() self._kernelCon = None self._ctrl_broker = None # Create yoton-based timer self._timer = yoton.Timer(0.2, oneshot=False) self._timer.bind(self.mainLoopIter) # Kernel process and connection (these are replaced on restarting) self._reset() # For restarting after terminating self._pending_restart = None
def _commandRestart(self, msg): # Almost the same as terminate, but now we have a pending action self._pending_restart = True # Recreate the info struct self._info = ssdf.copy(self._originalInfo) # Update the info struct new_info = ssdf.loads(msg.split("RESTART", 1)[1]) for key in new_info: self._info[key] = new_info[key] # Restart now, wait, or initiate termination procedure? if self._process is None: self.startKernel() elif self.isTerminating(): pass # Already terminating else: self.terminate("for restart")