Javascript 带有setTimeout的Python Shell
我使用以下命令运行test.js:Javascript 带有setTimeout的Python Shell,javascript,python,shell,Javascript,Python,Shell,我使用以下命令运行test.js: var power_meter = require('./power-meter'); var pm = new power_meter.PowerMeter(); function a() { var power_instant = 123; pm.broadcast(power_instant); setTimeout(a, 249); } a(); 输出是 123 123 现在,我想使用python shell从python脚本导入一
var power_meter = require('./power-meter');
var pm = new power_meter.PowerMeter();
function a() {
var power_instant = 123;
pm.broadcast(power_instant);
setTimeout(a, 249);
}
a();
输出是
123
123
现在,我想使用python shell从python脚本导入一个值:
var PythonShell = require('python-shell');
var pyshell = new PythonShell('7powerx.py');
var power_meter = require('./power-meter');
var pm = new power_meter.PowerMeter();
pyshell.on('message', function (message) {
console.log(message);
var power_instant = message;
pm.broadcast (power_instant);
});
// end the input stream and allow the process to exit
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
我已尝试设置“setTimeout(a,249);”
a()
在任何地方,但没有任何成功。
脚本在大约5分钟后启动并进行输出,但随后再次停止,一段时间后再次工作片刻。
我需要设置“设置超时”,但不知道在哪里
有什么想法吗
更新。
我的pythonScript中有一个时间函数,当我将其设置为0.0时,它可以工作,但我的树莓PI崩溃了。因此存在snych/定时问题。问题已解决:
对于循环过程,我需要从以下内容开始:
var pyshell = new PythonShell('test.py',{scriptPath:"./", pythonOptions: ['-u']});
我希望这对其他人也有帮助