Comments (12)
Thanks for the issue @alicoding, it's definitely a bug; Ctrl+C should kill all three.
They should be registered as children of the process and my understanding of unix is that killing a parent kills all children. Maybe this assumption is wrong.
I guess the brute-force(ish) way to do this is listen for the TERM signal and manually dispatch it to all other processes. Maybe we should be generically doing this anyway (i.e. for any kill signal, like SIGHUP or SIGUSR*)?
from parallelshell.
I was digging into this with @alicoding and we found that the problem was actually when you have a parallelshell child process exit with non-zero status code. It doesn't kill the other parallelshell child processes. Here's an example with a dummy sleep script:
Jons-MacBook-Pro:nsleep jbuck$ ./node_modules/.bin/parallelshell "node index.js 1000 1" "node index.js 10000 0"
nsleep.pid = 13373, sleeping for 10000ms
nsleep.pid = 13372, sleeping for 1000ms
nsleep.pid = 13372, slept for 1000ms
`node index.js 1000 1` failed with exit code 1
Jons-MacBook-Pro:nsleep jbuck$ ps
PID TTY TIME CMD
13006 ttys003 0:00.06 -bash
13373 ttys003 0:00.08 node index.js 10000 0
Jons-MacBook-Pro:nsleep jbuck$ nsleep.pid = 13373, slept for 10000ms
ps
PID TTY TIME CMD
13006 ttys003 0:00.06 -bash
Jons-MacBook-Pro:nsleep jbuck$
I also thought that if the parent process dies the child processes die so I'm not sure why it's continuing to run in the background
from parallelshell.
Also, this exactly matches the behaviour of the &
operator.
If you use the wait
command, then you have to wait for all processes to exit before getting the terminal prompt which is more intuitive:
node index.js 1000 1 & node index.js 5000 0 & wait
from parallelshell.
Should parallelshell kill all child processes when one of them exits with a non-zero error code? Or atleast make sure the terminal prompt doesn't come up when one of them dies? I think it's more intuitive, but it is a different behaviour. Maybe put it behind some sort of a flag, -w/--wait so it kinda acts like the bash wait
built-in?
from parallelshell.
The original design intention was for parallelshell to close all child processes every time if either one of the processes died, or you killed the parallelshell task. This is primarily because if you're killing it, or another process died - things have probably gotten messed up and you're going to re-run it all anyway. Most stuff behind parallelshell will either be build scripts or something like nodemon - so making it kill everything doesn't end the world, as you can get back to where you were by just re-running the command.
However, if you have a better idea (which it sounds like you do with -w
) then I'd love to see a PR. I guess what I'd like to see is: default behaviour kills all processes on crash or kill, adding -w
will wait until all processes finish or crash, ctrl+c kills all regardless of -w
.
from parallelshell.
hey, I could build something, but if it comes to parsing args - you mind the use of commander or similar helpers?
from parallelshell.
I'd rather keep this to 0 dependencies, but if you absolutely need to - go for it.
from parallelshell.
Hi all, any plan on merging the fix? I need this!
from parallelshell.
Hi guys, I love using parallelshell
on Windows
. I would really appreciate if you could merge the PR.
from parallelshell.
PR can be merged when notes are addressed. Feel free to take the contents of the PR and make the changes yourself, then submit a new PR.
from parallelshell.
It appears a pull request was merged to fix this issue, issue should be closed?
from parallelshell.
from parallelshell.
Related Issues (20)
- Why BrowserSync over Webpack-dev-server? HOT 1
- Issue with assigning variables HOT 5
- Feature request: Prefix output with (colored?) indicator of which process it came from HOT 1
- Suggestions for why parallelshell breaks node-notifier?
- Some output goes to the wrong terminal tab with two tabs open HOT 4
- Same argument passed to all shells? HOT 1
- Exit code is 0 when first command succeeds and second fails HOT 4
- fails on node8 HOT 3
- child_process throwing error ('"cwd" must be a string') HOT 24
- /usr/bin/env: βnode\rβ: No such file or directory ... HOT 9
- Allow 3.0 to be backwards compatible with < Node 8 HOT 6
- TypeError: "cwd" must be a string HOT 3
- New release? HOT 5
- Node 10.x version check fails HOT 9
- child_process throwing error ('"cwd" must be a string') HOT 2
- ERR_INVALID_ARG_TYPE error for Node v10.5.0 HOT 7
- The "options.cwd" property must be of type string. Received type function HOT 36
- Please do a release with the version check fork! HOT 7
- The "options.cwd" property must be of type string. Received type function HOT 1
- npm ERR! code ELIFECYCLE HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parallelshell.