Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): remove useless child.emit #733

Merged
merged 1 commit into from
Jun 27, 2022
Merged

Conversation

Anillc
Copy link
Member

@Anillc Anillc commented Jun 27, 2022

child.emit 并不会发送信号到进程,应该使用 child.killctrl-c 看上去会给子进程都发送 SIGINT ,这个我还没查到相关资料。不过不管怎么说, child.emit 都是没有工作的。

@codecov
Copy link

codecov bot commented Jun 27, 2022

Codecov Report

Merging #733 (c92284f) into master (16ae7a0) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #733   +/-   ##
=======================================
  Coverage   90.17%   90.17%           
=======================================
  Files          69       69           
  Lines        8206     8206           
  Branches     1382     1382           
=======================================
  Hits         7400     7400           
  Misses        806      806           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16ae7a0...c92284f. Read the comment docs.

@Anillc
Copy link
Member Author

Anillc commented Jun 27, 2022

https://en.wikipedia.org/wiki/Process_group

https://stackoverflow.com/questions/12753035/sending-sigint-from-keyboard-to-piped-commands-in-bash

看上去是因为 Ctrl-C 会发送到整个 Process group, 所以所有进程都能收到 SIGINT

@shigma
Copy link
Member

shigma commented Jun 27, 2022

给 child 直接 kill 的话,child 能自己处理退出前的流程吗

@Anillc
Copy link
Member Author

Anillc commented Jun 27, 2022

kill 只是给 child 发一个信号,如果 child 要处理退出的话是可以的, child 里的 process.on('SIGINT') 也是有正常工作的。

另外如果要收到 SIGINT 不退出的话只需要让 stdin 读数据就能阻止退出 (process.stdin.resume()) 。

@shigma
Copy link
Member

shigma commented Jun 27, 2022

那既然是发送到进程组,为什么这行代码不直接删掉呢?

@Anillc
Copy link
Member Author

Anillc commented Jun 27, 2022

看上去确实可以,那么我把他删掉吧。之前是考虑到我会给 cli 发 SIGINT 来结束 koishi 所以这样改的。但是我知道进程组后就决定给进程组的所有成员发 SIGINT

@Anillc Anillc changed the title fix(cli): use child.kill to send sigint chore(cli): remove useless child.emit Jun 27, 2022
@shigma shigma merged commit d25ae72 into koishijs:master Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants