- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的 NodeJS 代码如下:
[myFile.js]
var path = require("path");
var cp = require("child_process");
var child = cp.spawn( "python",["HelloWorld.py"], { stdio:'pipe', });
child.stdout.on('data', (data) => {
console.log(`CHILD stdout: ${data }`);
});
child.stderr.on('data', (data) => {
console.log(`CHILD stderr: ${data}`);
});
process.on("SIGINT",()=>{
// close gracefully
console.log("Received SIGINT");
})
child.on('exit',(code)=>{console.log(`child Process exited with code ${code}`)})
和Python脚本如:
[HelloWorld.py]
print 'Hi there'
import time
time.sleep(5)
我想优雅地管理关闭,但是当我通过以下方式在命令行启动此代码时:
> node myFile.js
然后按 control-C,我将其打印到控制台:
^CReceived SIGINT
CHILD stdout: Hi there
CHILD stderr: Traceback (most recent call last):
File "HelloWorld.py", line 3, in <module>
time.sleep(5)
KeyboardInterrupt
child Process exited with code 1
表示python(在子进程中运行)收到了'^C'键盘事件。但是,我更愿意更优雅地退出子进程,而不是因键盘中断而崩溃。
我尝试了各种组合 options.stdio ,包括 [undefined,'pipe','pipe']
(这不起作用)和 ['ignore','pipe','pipe']
(这导致了子进程崩溃),我尝试了 worker.stdin.end()
(这也导致了子进程崩溃)。
有没有办法不从父 NodeJS 进程继承标准?
最佳答案
RTFM:设置options.detached to true
是阻止传播终止信号的原因,这(令人惊讶)是当父进程被终止时附加的子进程如何被终止的......
关于node.js - 防止信号传播到子进程 (NodeJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41774895/
需要帮助将这些给定的数字打印成星号,但我是编程新手;我该怎么做? #include int main(void) { int a[5]={20,1,5,15,12}; int i=0
使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息. 我见
我不知道制服在内存中是如何表示的。 制服似乎会占用宝贵的寄存器空间,但它们最终会传入/通过/传出到全局内存中,对吗? 制服不用时情况会发生变化吗?编译器可以将它们优化掉吗?--在这种情况下,我已经将无
我正在尝试在名为“timeclock”的模型上记录“time_in”和“time_out”记录。这是我想做但无法开始工作的事情! 检查最后一个时钟条目,看看它是否同时填充了“time_in”和“tim
我想听听您如何解决这种编程任务!?每种类型(OPER = 1 类型)对应一种特定的信息。 这只是大约 10 个具有相同结构的规范之一。首选创建这些“转换器”(协议(protocol))的通用方法。 最
我正在使用 Rest API(NodeJS、Express)和 PostgreSQL 制作 React-Native 应用。 在我的本地机器上托管时一切正常。当 API 托管在我的机器上并且 Post
我是一名优秀的程序员,十分优秀!