-
Notifications
You must be signed in to change notification settings - Fork 222
Description
Hi,
I'm trying to send data to a python script that controls motors on my Raspberry Pi, but I'm confused about the recommended way of doing this. Up until now I was using something like:
function runMotor (speed) {
var shell = new PythonShell('./script.py');
shell.send(speed);
shell.end( function(err) {
if (err) throw err;
}
);
}
But I was getting some latency between sending the command and the motor moving, which I think is because there's a heavy overhead with instantiating a new instance of PythonShell each time and importing the modules every time on the python side.
I tried moving the shell creation outside of the function, and not calling shell.end() immediately, but then it blocks, I assume because it only starts reading the input once you call shell.end(). You also can't instantiate the shell and call send() and end() multiple times, so what is the proper way to do this?
I saw you mention using var shell = PythonShell.run('./script.py')
instead in this issue: #16 (comment), but when I try that it complains "Error: write after end".
Is there a way to keep the script 'open' so that I don't incur an overhead from calling the constructor over and over and re-importing the modules the python script needs over and over?