Comments (8)
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.
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.
Fair enough, that is a good argument.
Just out of curiosity... What kind of clean-up do you do?
from threads.js.
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.
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.
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.
@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.
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)
- error TS7016: Could not find a declaration file for module 'threads' HOT 1
- Worker Path Module not found HOT 1
- "Error: Cannot find module '/engine-learn/Worker'" or "Error: expose() called in the master thread." HOT 1
- No instantiations of threads.js workers found in TypeScript/Webpack setup HOT 1
- React Usage
- subscribe won't propagate falsey values
- Trying to use Transfer() to no avail... HOT 1
- Observable values not being returned until the process finishes HOT 3
- SharedArrayBuffer support?
- Promised Observable HOT 1
- ReferenceError: importScripts is not defined when using await import HOT 2
- Add compatibility for the bun runtime version of Worker HOT 2
- feature request: support "pinning" tasks to workers
- Could i use this in my vite project? HOT 2
- ability to disable the process hooks added by #150 HOT 1
- Deno support? HOT 3
- Inject full path to Worker where it used, not where declared
- Error in readme (404) HOT 1
- What is the correct way to terminate a worker via Thread and BlobWorker?
- threads in Legacy (Safari 7) browser
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 threads.js.