GithubHelp home page GithubHelp logo

Subprocess pid is always 0 about child_process HOT 5 CLOSED

skpm avatar skpm commented on June 14, 2024
Subprocess pid is always 0

from child_process.

Comments (5)

mathieudutour avatar mathieudutour commented on June 14, 2024

Ah right, thanks for the nice bug report!

A potential fix would be to use a getter instead of assigning the value directly. Want to send a PR?

from child_process.

halffullheart avatar halffullheart commented on June 14, 2024

Yes, I would be happy to try to put together a fix. Can you help me understand why setImmediate() is being used?

From what I can tell, the node API returns a subprocess with the correct PID synchronously, e.g. this works:

const { spawn } = require('child_process')
console.log(spawn('ls').pid) // => non-zero number

Using a getter to call processIdentifier() would still return 0 in a case like this, right?

from child_process.

mathieudutour avatar mathieudutour commented on June 14, 2024

Hum you're right. Tbh I can't remember why I wrapped it in a setImmediate.
I'm guessing it had to do with making sure the callback is called at the end of the event loop. But maybe it's not necessary

from child_process.

anyab5 avatar anyab5 commented on June 14, 2024

Another problem with using setImmediate is that exceptions such as :
{ Error: An Obj-C exception occurred. at [native code] (/) at spawn ..... nativeException: <NSException> Couldn't posix_spawn: error 7, line: 817, column: 16
will not get caught in the general catch flow and error will not get triggered.
From client perspective we cannot know when and what exception occurred.
I created a PR for removing setImmediate if that sounds reasonable to you.

from child_process.

mathieudutour avatar mathieudutour commented on June 14, 2024

fixed in 0.4.2

from child_process.

Related Issues (7)

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.