/* *SendscodetoGAPkerneltoexecute,callingcallbackwiththeresults. * *Becausesomevisualizationsshouldbeinteractive,wewanttheabilityto *callGAPcodefromthenotebookclient,usingJavaScript,andreceive *resultsback,onwhichwecanoperateinJavaScript.Thisfunction *enablesthatfunctionality. * *IftheGAPcodeyieldsaresult,thiscallscallback(result,null). *IftheGAPcodeyieldsanerror,thiscallscallback(null,error).
*/
window.runGAP = function ( code, callback )
{ // if the kernel is not ready, just write to the output cell and quit. if ( !Jupyter || !Jupyter.notebook || !Jupyter.notebook.kernel ) return callback( null, 'JavaScript-based output must be re-evaluated when the notebook'
+ ' is reloaded. (Re-run the cell to clear this problem.)' ); // the purpose of the following variables is explained further below var errorMessages = [ ]; var timeout = null; // send code to the kernel, with the options specified below
Jupyter.notebook.kernel.execute( code, {
iopub : {
output : function ( message ) { // results come back in message.content.data, usually // message.content.data["text/plain"], so if that's present, // that's a success: if ( 'data' in message.content ) return callback( message.content.data, null ); // errors come back in message.content.text, so if we don't // have even that, then I have no idea what's going on, so // yield an error now: if ( !( 'text' in message.content ) ) return callback( null, message.content ); // we have some text, which may be some or all of an error // message; more messages may be coming. so store this one // in an array of error messages and start a 200ms timeout // to see if we get any further error messages. // (if any former timeout was running, clear it first.)
errorMessages.push( message.content.text ); if ( timeout !== null )
clearTimeout( timeout );
timeout = setTimeout( function () { // 200ms has passed, so send error to callback
callback( null, errorMessages.join( '\n' ) );
}, 200 );
},
clear_output : function ( message ) { // could put code here if you want to monitor these // messages, but I do not yet need to do so
}
},
shell : {
reply : function ( message ) { // could put code here if you want to monitor these // messages, but I do not yet need to do so
}
},
input : function ( message ) { // could put code here if you want to monitor these messages, // but I do not yet need to do so
}
}, { // could put code here if you want to monitor these messages, but I // do not yet need to do so
} );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.