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):
varpyshell=newPythonShell('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.
importsys, json# simple JSON echo scriptforlineinsys.stdin:
printjson.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)throwerr;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?
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):
The python is the same as your echo script.
Now, if I close the connection after the above code, then I get all the messages:
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?