node.js - Raspberry PI 上 NodeJS 中的长 setTimeout

标签 node.js raspberry-pi

我有一个奇怪的问题,长 setTimeouts 不会在 Raspberry PI 上触发,但它们会在 Ubuntu/x64 和 OSX 上触发。

'use strict';

const delay = 1000 * 3600 * 8;
const date = new Date();

date.setTime(new Date().getTime() + delay);
console.log('Alarm set to', date.toString());

setTimeout(function () {
    console.log('Alarm!', new Date());
}, delay);

此代码将在 Ubuntu/x64 上 8 小时后回显 Alarm!,但它永远不会在 RPI 上触发。

作品:

  • Ubuntu/x64
  • 操作系统

不起作用:

  • RPI b+ 与 Raspian 7( Node 6.1)
  • RPI 3 与 Raspian 8( Node 4.4.4、6.0 和 6.1)

根据ps,脚本处于Sl状态:可中断 sleep (等待事件完成),是多线程的(使用CLONE_THREAD,比如NPTL pthreads 做)。

在此代码的更复杂版本中,我可以通过 Web UI 控制脚本,“警报”将在设置时间后关闭,但仅当我访问 Web UI 时(唤醒应用程序? ).

这是 NodeJS 错误还是我在做一些时髦的事情?

最佳答案

添加这个解决它,直到 NodeJS 问题得到解决。

// Every 20 min to keep awake
setInterval(() => 1, 1000 * 60 * 20);

关于node.js - Raspberry PI 上 NodeJS 中的长 setTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37153589/

相关文章:

node.js - 在 NodeJS 中批量写入 DynamoDB 时的指数退避

python - 在 Python 中放置变量

html - 如何在 Raspberry Pi 4 的 kiosk 模式下使垂直滚动条在 chromium-browser 中更大和/或更靠左?

ios - 使用它作为 BLE 外设在 raspberry-pi 上配置 wifi

带有 netcat 的 linux 脚本在 x 小时后停止工作

node.js - NodeJS Buffer 是异步的还是同步的?

javascript - 火力地堡 : Wait For Async and Push to an array

javascript - 使用 Sinon 模拟 require() 函数

node.js - 使用 IISnode 运行 Keystone.js

raspberry-pi - kworker 在空闲系统上的 CPU 使用率很高