Skip to content

Commit

Permalink
Ensure that all sockets are connected after kernel restart (#887)
Browse files Browse the repository at this point in the history
* Ensure that all sockets are connected after kernel restart

* Guard against simultaneous kernel restarts
  • Loading branch information
lgeiger authored and t9md committed Jun 22, 2017
1 parent 9b1a5c3 commit f9c2406
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/zmq-kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export default class ZMQKernel extends Kernel {
this.ioSocket.on("message", this.onIOMessage.bind(this));
this.stdinSocket.on("message", this.onStdinMessage.bind(this));

this.monitor(done);
}

monitor(done: ?Function) {
try {
let socketNames = ["shellSocket", "controlSocket", "ioSocket"];

Expand Down Expand Up @@ -168,6 +172,10 @@ export default class ZMQKernel extends Kernel {

restart(onRestarted: ?Function) {
if (this.kernelProcess) {
if (this.executionState === "restarting") {
return;
}
this.setExecutionState("restarting");
this.shutdown(true);
this._kill();
const { spawn } = launchSpecFromConnectionInfo(
Expand All @@ -177,14 +185,14 @@ export default class ZMQKernel extends Kernel {
this.options
);
this.kernelProcess = spawn;
this.setExecutionState("idle");
this.monitor(() => {
if (onRestarted) onRestarted(this);
});
} else {
log("ZMQKernel: restart ignored:", this);
atom.notifications.addWarning("Cannot restart this kernel");
if (onRestarted) onRestarted(this);
return;
}

log("ZMQKernel: restart ignored:", this);
atom.notifications.addWarning("Cannot restart this kernel");
if (onRestarted) onRestarted(this);
}

// onResults is a callback that may be called multiple times
Expand Down

0 comments on commit f9c2406

Please sign in to comment.