Comments (3)
Also would like to say ty for your work talking about using npm as a build too, its helped me a lot.
I agree, using &
in place of parallelshell
seems to work in the few cases where I've tried it, but maybe I'm missing something.
Note that I think you may also sometimes need the wait
command to stop any long-running parallel processes properly with ctrl-c
or whatever, otherwise they'll still be running in a detached state in the current shell when the parent command exits.
So say you wanted to run your dev server and watch local files for changes in order to rebuild, you might have something like,
npm run devserver & npm run watch & wait
From wait docs:
wait [jobspec or pid ...]
Wait until the child process specified by each process ID pid or job specification jobspec exits and return the exit status of the last command waited for. If a job spec is given, all processes in the job are waited for. If no arguments are given, all currently active child processes are waited for, and the return status is zero. If neither jobspec nor pid specifies an active child process of the shell, the return status is 127.
from parallelshell.
&
is pretty sweet, and I'd absolutely recommend you use it for a certain number of cases. However, &
offers specific semantics over what parallelshell does.
For starters, &
creates a job from a process, and puts it in the background. This means that the process is no longer attached to your shell env, and when you leave the shell env the task will continue to run. Take for example the following npm script:
"scripts": {
"foo": "sleep 100 & echo foo"
}
Now if I run this:
$ npm run foo
> [email protected] foo /<snip>
> sleep 100 & echo foo
foo
$
The sleep
process outlives the npm script!
$ ps -ef | grep sleep
501 29701 1 0 3:55pm ttys002 0:00.00 sleep 100
Also the problem with this, is that background jobs' exit codes are ignored, meaning if it fails you wont know about it. As @jedrichards suggested I could use wait
which will hang until sleep 100
finishes, and propagate the exit code. However this has a couple of problems:
- As far as I know,
wait
isn't available on windows. - Pressing
ctrl-c
will terminatewait
, but does not terminate any jobs (meaning they're still running in the background)
So for a task where you just want to build things in parallel and just wait for the exit codes, and don't care about windows support - use &
and wait
.
If you have a project where you need Windows, or a task where you need to run processes which wont quit until you quit them, then parallelshell is the right tool for this job.
from parallelshell.
Awesome.
Thanks for the clarity @keithamus. And thanks for pointing out the wait
command @jedrichards.
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.