node-python example
Example 1: how to make a python node
class Node:
def __init__(self, value, link_node=None):
self.value = value
self.link_node = link_node
def set_link_node(self, link_node):
self.link_node = link_node
def get_link_node(self):
return self.link_node
def get_value(self):
return self.value
Example 2: stop python script nodejs
var python_process;
router.get('/start_python', function(req, res) {
var PythonShell = require('python-shell');
var pyshell = new PythonShell('general.py');
pyshell.end(function (err) {
if (err) {
console.log(err);
}
});
python_process = pyshell.childProcess;
res.send('Started.');
});
router.get('/stop_python', function(req, res) {
python_process.kill('SIGINT');
res.send('Stopped');
});