pixiedust / pixiedust_node

Jupyter magic to allow Node.js code to run in a notebook
https://medium.com/ibm-watson-data-lab/running-node-js-notebooks-in-watson-studio-a8f6545d8299
Apache License 2.0
213 stars 24 forks source link

print doesn't create any output after display was invoked #22

Closed ptitzler closed 6 years ago

ptitzler commented 6 years ago

PD 1.1.7, PD_node 0.2.1

import pixiedust_node
%%node
print('Hello world')

Hello world

%%node
var x = [];
x.push({x:1, y:2});
display(x);

...

%%node
print('Hello world')

no output

glynnbird commented 6 years ago

You can run the Node.js sub-process from the command-line with:

node pixiedust_node/pixiedustNodeRepl.js 

and type some commands:

var a = 1;

{"_pixiedust":true,"type":"variable","key":"a","datatype":"number","value":1}

var b = 2;

{"_pixiedust":true,"type":"variable","key":"b","datatype":"number","value":2}

var c = 3;

{"_pixiedust":true,"type":"variable","key":"c","datatype":"number","value":3}

display(c)
{"_pixiedust":true,"type":"display","data":3}

display(a)
{"_pixiedust":true,"type":"display","data":1}

Notice how the second call to display works just fine.

But within a Notebook, after the first call to display no subsequent Node.js cells work. The cell data isn't even transferred to the Node.js process as far as I can see

glynnbird commented 6 years ago

Although the Node.js repl behaves on its own, calling display somehow disturbs the connection between Python & Node.js

If I comment out this line https://github.com/ibm-watson-data-lab/pixiedust_node/blob/master/pixiedust_node/node.py#L47 then everything works again. This is the line that moves Python variables to Node.js if they have changed.

Another fix is to call node.cancel() in a Python cell. This sends "\r\n.break\r\n" from Python to the Node.js repl and seems to unblock the communication.

glynnbird commented 6 years ago

Fixed in pixiedust_node 0.2.2.

It was fixed by preventing Python --> Node variable migration when the variable names were Node.js reserved words e.g. true.