-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Description
Hey - I'm trying to the send/message functionality on python-shell to exchange data between a long-running python script and node, but I'm seeing that the messages don't get handled till I end the input stream. For example, the following sample code does not invoke the 'message' callback (or 'close' or 'error):
var pyshell = new PythonShell('python/helloworld.py', options);
pyshell.send({'hello': 'world'});
pyshell.on('message', function(message) {
console.log("message - ", message);
}).on('close', function (result) {
console.log("close - ", result);
}).on('error', function (err) {
console.log("error")
});
The python is the same as your echo script.
import sys, json
# simple JSON echo script
for line in sys.stdin:
print json.dumps(json.loads(line))
Now, if I close the connection after the above code, then I get all the messages:
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
This won't work for me as my python script maintains state and I don't want to re-run the script every time. I'd rather have a long running child process I could pass messages back and forth from. This seems like a bug. Any suggestions?
Metadata
Metadata
Assignees
Labels
No labels