0

I was executing Nodejs script from jupyter notebook, and the output of the Nodejs output was not showing in the notebook output. I went through stackoverflow and found this solution Constantly print Subprocess output while process is running. But, this solution only talks about processing lines. The way the Nodejs code was written is that it outputs a character such as "#" when it processes a file. It looks like a progress bar on command line. As there is no newline character, while using the solution from the link above, all of these "#" signs are accumulated and a chunk of them are printed after the completion of Nodejs code execution. What I would like to see is a combination of newline based and a time based output.

For example, if Nodejs processed 10 documents, on the command line I would see ten # signs appear in real time (one at a time). Let us say after 10 documents were processed a new line was printed (as shown below). It takes 1 sec to process each file.

"##########"

"##########"

"##########"

If I make it a combination of time based output and newline based output. For a time limit of 7 sec, I should be able to see the output below. Quotes are used to show the time interval.

"#######""###"

"#######""###"

7 sec, 3 sec (because encountered a new line), then 7 sec .....

or

"#######""###"

"####""######"

7 sec, 3 sec (because encountered a new line), 4 sec (combined with previous 3 sec makes 7 sec), 6 sec (because encountered a new line) ......

If someone can come up with a better solution where a real time output of each # can be displayed on the console, python idle or jupyter notebook output, that would be perfect.

Raj006
  • 562
  • 4
  • 18

1 Answers1

0

Exploring this for a while I came across this post https://medium.com/ibm-watson-data-lab/nodebooks-node-js-data-science-notebooks-aa140bea21ba. The "pixiedust" and "pixiedust_node" python modules listed will ensure the nodejs code to run in jupyter notebook. Not only they let execute the nodejs code within the jupyter notebook, they let you use the native python "print" command to print the output. So, I could include the nodejs code I was calling within the jupyter notebook, and I can replace the "process.stdout.write('#')" call with "print" and get the same result as I get when I run the nodejs code in the command line. I haven't tested this fully, but I am assuming, the "process.stdout.write('#');" might work as well without replacing it with a "print" command. Either way, this will solve my problem. Once I test it fully, I will accept this as the answer.

Raj006
  • 562
  • 4
  • 18
  • According to github.com/pixiedust/pixiedust_node, "The output of the Node.js process is parsed by pixiedust_node to handle the use of functions display/print/store/html/image". This basically excludes my use case. I am not deleting this answer as it could be useful for someone looking to run Node.js inside jupyter notebook. – Raj006 Nov 17 '18 at 20:02