GithubHelp home page GithubHelp logo

Comments (8)

andywer avatar andywer commented on August 24, 2024

Yeah, the pool shutdown is a bit tricky, since usually the pool is not terminated right away after doing an initial chunk of work.

That kill vs on('exit') situation is interesting. Maybe it might be a good idea to change the .kill() behavior, like performing a child.exit() and setting some timeout to only call child.kill() if it didn't already shut down during this timeout?

from threads.js.

mijay avatar mijay commented on August 24, 2024

I would argue that sendAll would be both simpler to implement and more logical api to have in Pool. Plus that can be easily implemented cross-platform. Of course, then everyone who want to support cleanup scenario like I've described, will have to do it themselves, but that sounded more like a FAQ topic.

from threads.js.

andywer avatar andywer commented on August 24, 2024

Fair enough, that is a good argument.

Just out of curiosity... What kind of clean-up do you do?

from threads.js.

andywer avatar andywer commented on August 24, 2024

If you need the sendAll urgently I'd say open a PR and get credited in the changelog. I might implement it as well, but it's not a high priority to me.

Anyway I can publish v0.7.3 containing the unhandled promise rejection handler today.

from threads.js.

mijay avatar mijay commented on August 24, 2024

I ended up using hack 1 and it works for now, just not beautiful enough - so no urgency.

I am using a pool of runners to run bunch of selenium tests in parallel, so I need to shutdown the driver used by each thread properly when there are no more tests left.

from threads.js.

AslanGoldenhour avatar AslanGoldenhour commented on August 24, 2024

Just adding to this… I'm having trouble releasing my database connection from within a worker when the worker fails prematurely. That's my primary use case for cleanup. That and global.gc() when running Node with the --expose-gc flag.

EDIT: I didn't see code before I first posted…

{
    job.destroy();                    // to prevent memory leak
    this.idleThreads.push(thread);
    this.emit('threadAvailable');

    if (this.idleThreads.length === this.threads.length) {
      // run deferred to give other job.on('done') handlers time to run first
      setTimeout(() => { this.emit('finished'); }, 0);
    }
}

What are your thoughts on adding something just before job.destroy() for manual cleanup processes? e.g. (but with ES6)
if (typeof job.cleanup === "function") await job.cleanup();

from threads.js.

andywer avatar andywer commented on August 24, 2024

@ZenModeRy Thanks for sharing your thoughts. To make if (typeof job.cleanup === 'function') possible, we would need to extend the API of Job, so it's not exactly a "done in ten minutes" change.

But a proper way to clean-up after a job would be nice. I will put it on the "version 1.0 wishlist" #54 😉

from threads.js.

andywer avatar andywer commented on August 24, 2024

I think this should be fixed in v1.0. Closing. Feel free to re-open if it still happens in 1.0.

from threads.js.

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.