ines / juniper

🍇 Edit and execute code snippets in the browser using Jupyter kernels
https://ines.github.io/juniper/
MIT License
224 stars 38 forks source link

Loading status stays forever if no stdout is received #8

Closed ashtonmv closed 3 years ago

ashtonmv commented 3 years ago

First of all, thanks @ines for creating an amazing tool.

My only problem is I occasionally want to create cells that don't return anything to stdout, and then Juniper's status remains a misleading "loading" even though the cell has finished executing. For example,

// settings used for the screenshot below
new Juniper({
  repo: "pyiron/pyiron",
  isolateCells: false,
})
Screenshot

If I understand correctly, it's because the MyBinder server doesn't send any of the specific messages that Juniper is looking for in the first cell, e.g. a stdout message or failure to trigger outputArea.model.clear() and insert something other than msgLoading.

So I'm trying to figure out how to listen for a more generic "finished" event sent back by the mybinder server - basically, whatever background event triggers the Jupyter cell input-prompt to change from In [*] to In [1] on MyBinder itself. I will keep trying to figure it out, but maybe someone else has more of a clue than I do.

ashtonmv commented 3 years ago

Instead of actually changing juniper, I basically got what I wanted by modifying the jupyter KernelFutureHandler's _handleDone function to dispatch an event to the document that I can then listen for.

within juniper.min.js (lines imported from jupyterlab/future)

(t.prototype._handleDone = function () {

    // the existing _handleDone function
    this._testFlag(o.KernelFutureFlag.IsDone) || (this._setFlag(o.KernelFutureFlag.IsDone), this._done.resolve(this._replyMsg), this._disposeOnDone && this.dispose());

    // add and dispatch a new event
    var event = new CustomEvent('juniper-executed', { detail: this._replyMsg });
    document.dispatchEvent(event);
}),

This doesn't actually remove juniper's "loading" status, but it at least provides a hook by which I can modify the active juniper-cell accordingly. And dispatching this._replyMsg is nice because it contains a status (event.detail.content.status) and the cell's execution count on the server (event.detail.content.execution count).