Skip to content

Commit

Permalink
fix bug where npm calls ran CPU at 100% - fixes issue #16
Browse files Browse the repository at this point in the history
  • Loading branch information
glynnbird committed Jan 3, 2018
1 parent 7326b59 commit d396c31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pixiedust_node/nodestdreader.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -61,4 +66,4 @@ def run(self):

except Exception as e:
print(line)
print(e)
print(e)
5 changes: 5 additions & 0 deletions pixiedust_node/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pixiedust_node/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down

0 comments on commit d396c31

Please sign in to comment.