Giter Site home page Giter Site logo

Comments (3)

jedrichards avatar jedrichards commented on July 29, 2024

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.

keithamus avatar keithamus commented on July 29, 2024

& 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 terminate wait, 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.

igregson avatar igregson commented on July 29, 2024

Awesome.

Thanks for the clarity @keithamus. And thanks for pointing out the wait command @jedrichards.

from parallelshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.