diff --git a/pixiedust_node/nodestdreader.py b/pixiedust_node/nodestdreader.py index 14a7b35..34afbd4 100644 --- a/pixiedust_node/nodestdreader.py +++ b/pixiedust_node/nodestdreader.py @@ -1,6 +1,7 @@ from pixiedust.display import * from pixiedust.utils.shellAccess import ShellAccess from threading import Thread +from threading import Event import IPython import json import pandas @@ -17,14 +18,18 @@ class NodeStdReader(Thread): def __init__(self, ps): super(NodeStdReader, self).__init__() + self._stop_event = Event() self.ps = ps self.daemon = True self.start() + def stop(self): + self._stop_event.set() + def run(self): - + # forever - while(True): + while(self._stop_event.is_set() == False): # read line from Node's stdout line = self.ps.stdout.readline() @@ -61,4 +66,4 @@ def run(self): except Exception as e: print(line) - print(e) \ No newline at end of file + print(e) diff --git a/pixiedust_node/npm.py b/pixiedust_node/npm.py index cb32f05..40fff3c 100644 --- a/pixiedust_node/npm.py +++ b/pixiedust_node/npm.py @@ -30,8 +30,13 @@ def cmd(self, command, module): # create thread to read this process's output t = NodeStdReader(ps) + + # wait for the sub-process to exit ps.wait() + # tell the thread reading its output to stop too, to prevent 100% CPU usage + t.stop() + def install(self, module): self.cmd('install', module) diff --git a/pixiedust_node/package.json b/pixiedust_node/package.json index ec4716a..2d47c1b 100644 --- a/pixiedust_node/package.json +++ b/pixiedust_node/package.json @@ -1,6 +1,6 @@ { "name": "pixiedust_node", - "version": "0.1.5", + "version": "0.1.6", "description": "Run Node.js cells in Jupyter notebooks with Pixiedust", "main": "pixiedustNodeRepl.js", "scripts": { diff --git a/setup.py b/setup.py index 9a0467f..21c7e99 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='pixiedust_node', - version='0.1.5', + version='0.1.6', description='Pixiedust extension for Node.js', url='https://github.com/ibm-watson-data-lab/pixiedust_node', install_requires=['pixiedust'],