Skip to content

Instantly share code, notes, and snippets.

@zcaceres
Created November 18, 2018 21:20
Show Gist options
  • Save zcaceres/03a30ca653e7f7a9f1d42b9f623ee7fd to your computer and use it in GitHub Desktop.
Save zcaceres/03a30ca653e7f7a9f1d42b9f623ee7fd to your computer and use it in GitHub Desktop.
Sample 1
class PythonConnector {
static server() {
if (!PythonConnector.connected) {
console.log('PythonConnector – making a new connection to the python layer');
PythonConnector.zerorpcProcess = spawn('python3', ['-u', path.join(__dirname, 'PythonServer.py')]);
PythonConnector.zerorpcProcess.stdout.on('data', function(data) {
console.info('python:', data.toString());
});
PythonConnector.zerorpcProcess.stderr.on('data', function(data) {
console.error('python:', data.toString());
});
PythonConnector.zerorpc = new zerorpc.Client({'timeout': TIMEOUT, 'heartbeatInterval': TIMEOUT*1000});
PythonConnector.zerorpc.connect('tcp://' + IP + ':' + PORT);
PythonConnector.connected = true;
}
return PythonConnector.zerorpc;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment