1- const registerKernelListeners = ( ) => {
2- try {
3- if ( IPython . notebook . kernel == null ) {
4- console . warn ( "Kernel not initialized. Waiting to register kernel event listeners" ) ;
5- setTimeout ( registerKernelListeners , 500 ) ;
6- return ;
7- }
8- } catch ( error ) {
9- console . warn ( "IPython not initialized. Waiting to register kernel event listeners" ) ;
10- setTimeout ( registerKernelListeners , 500 ) ;
11- return
12- }
1+ import { record as recordCommand } from './CommandRecorder' ;
132
14- const notebook = IPython . notebook ;
15- const handleKernelStatusChange = ( event , data ) => {
16- const kernelStatusEvent = new CustomEvent ( "kernelstatus" , {
17- detail : {
18- "type" : event . type ,
19- ...data
20- } ,
21- } ) ;
22- window . dispatchEvent ( kernelStatusEvent ) ;
23- } ;
24-
25- notebook . events . on ( 'kernel_created.Kernel' , handleKernelStatusChange ) ;
26- notebook . events . on ( 'kernel_reconnecting.Kernel' , handleKernelStatusChange ) ;
27- notebook . events . on ( 'kernel_connected.Kernel' , handleKernelStatusChange ) ;
28- notebook . events . on ( 'kernel_starting.Kernel' , handleKernelStatusChange ) ;
29- notebook . events . on ( 'kernel_restarting.Kernel' , handleKernelStatusChange ) ;
30- notebook . events . on ( 'kernel_autorestarting.Kernel' , handleKernelStatusChange ) ;
31- notebook . events . on ( 'kernel_interrupting.Kernel' , handleKernelStatusChange ) ;
32- notebook . events . on ( 'kernel_disconnected.Kernel' , handleKernelStatusChange ) ;
33- notebook . events . on ( 'kernel_ready.Kernel' , handleKernelStatusChange ) ;
34- notebook . events . on ( 'kernel_killed.Kernel' , handleKernelStatusChange ) ;
35- notebook . events . on ( 'kernel_dead.Kernel' , handleKernelStatusChange ) ;
36- }
37- registerKernelListeners ( ) ;
383
394const handle_output = function ( data ) {
405 // data is the object passed to the callback from the kernel execution
@@ -67,9 +32,24 @@ const handle_output = function (data) {
6732 }
6833} ;
6934
70- const execPythonMessage = function ( command , callback = handle_output ) {
35+ const execPythonMessage = function ( command , callback = handle_output , record = true ) {
7136 const { kernel } = IPython . notebook ;
72- const messageID = kernel . execute ( command , { iopub : { output : callback } } , { silent : false , stop_on_error : true , store_history : true } ) ;
37+ console . log ( "Kernel" , kernel . id , "executes" , command )
38+ if ( record ) {
39+ recordCommand ( kernel . id , command )
40+ }
41+ const messageID = kernel . execute (
42+ command ,
43+ {
44+ iopub : { output : callback }
45+ } ,
46+ {
47+ silent : false ,
48+ stop_on_error : true ,
49+ store_history : true ,
50+ netpyne_ui_triggered : true
51+ } ) ;
52+
7353
7454 return new Promise ( ( resolve , reject ) => GEPPETTO . on ( GEPPETTO . Events . Receive_Python_Message , ( data ) => {
7555 if ( data . data . id == messageID ) {
@@ -78,6 +58,10 @@ const execPythonMessage = function (command, callback = handle_output) {
7858 } ) ) ;
7959} ;
8060
61+ const execPythonMessageWithoutRecording = function ( command , callback = handle_output ) {
62+ return execPythonMessage ( command , callback , false )
63+ }
64+
8165const addslashes = function ( str ) {
8266 return ( str + '' ) . replace ( / [ \\ " ' ] / g, '\\$&' ) . replace ( / \u0000 / g, '\\0' ) ;
8367}
@@ -99,4 +83,4 @@ const evalPythonMessage = function (command, parameters, parse = true) {
9983 return execPythonMessage ( finalCommand , handle_output ) ;
10084} ;
10185
102- export { execPythonMessage , evalPythonMessage } ;
86+ export { execPythonMessage , evalPythonMessage , execPythonMessageWithoutRecording } ;
0 commit comments