I've this simple Python script print out a message every second:
#!/usr/bin/python
import time
while True:
print u"Message"
time.sleep(1)
I'm trying to integrate a 3rd party Python script with the above structure with Node.js using python-shell.
I'm having this JS script to get all messages from the Python script:
var PythonShell = require('python-shell');
var options = {
scriptPath: './'
};
var pyshell = new PythonShell('test.py',options);
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
But it seems, that the while True in Python cause that the on-event is not called. How can I solve this? Can I change the loop inside the Python script to something compatible with python-shell?
the while True in Python cause that the on-event is not called- True. Its an infinite loop.How can I solve this?- Remove the infinite loop.