Questions tagged [worker-thread]

The tag has no usage guidance.

75 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6 votes
0 answers
2k views

[Nodejs - worker-threads]: Is there an option for the main thread to wait till all worker threads are done?

Is there an option by which we can make the main thread wait until all worker threads are done? In the below code, mainThread.js simply creates workers. The worker takes long time to execute. In this ...
Kruthika C S's user avatar
5 votes
0 answers
843 views

Test worker thread with mocks

My Node application uses AWS SDK, and in order to mock it locally I am using Jest's manual mocks. Basically I am placing in __mocks__ folder barebone mock of AWS SDK that simulates methods I use - and ...
Yuriy Galanter's user avatar
5 votes
0 answers
4k views

worker.on('error') not working when unhandled rejection happens in the worker

worker.js async function main() { throw new Error('Bullocks!'); } setTimeout(async () => { await main(); }, 1000); main.js const { Worker } = require('worker_threads'); const worker = new ...
Bagas Wahyu Hidayah's user avatar
5 votes
1 answer
949 views

How to send message to multiple threads from another one?

I have a worker which creates MessageChannel and sends one of ports to main thread // worker1.js const { parentPort, MessageChannel } = require('worker_threads'); const { port1, port2 } = new ...
Artur Aralin's user avatar
4 votes
0 answers
310 views

tsconfig paths in worker_threads

I'm spinning up some node workers and need each worker to pull code from a path expressed in tsconfig's paths compiler options. How do you configure worker to acknowledge paths from tsconfig? here's ...
Tom Schreck's user avatar
  • 5,247
4 votes
0 answers
857 views

"Module did not self-register" error when trying to load bcrypt in worker thread

Sample project with issues: https://github.com/Suvitruf/bcrypt-child-process-crash-proof const {Worker, isMainThread} = require('worker_threads'); if(isMainThread) console.log("I'm ok, because I'...
Suvitruf - Andrei Apanasik's user avatar
3 votes
0 answers
550 views

how to work with response object in nodejs stream, exceljs and worker thread

I am using worker thread and stream at same time in node JS project. At initial I was not able to pass res object through main process to worker thread. I saw many stackoverflow question and solution ...
sabin maharjan's user avatar
3 votes
1 answer
932 views

Passing my stream to a worker thread node.js

I have to implement this custom method of Multer storage in order to encrypt file before saving it. I have implemented my function encrypt, which will comunicate with a worker thread. import { ...
ste9206's user avatar
  • 1,842
2 votes
0 answers
38 views

Using wokerpool on multi node.js processes running on the same server

I have a server with 6 CPU logical cores, there is 6 node.js (v 16) processes running express.js app within the server and managed by pm2 process manager, and I'm using Nginx proxy to load balance the ...
Basheer Shahrour's user avatar
2 votes
0 answers
484 views

Unable to import modules in node-worker-thread-pool

I am using node-worker-thread-pool package.I am unable to import certain node modules into my worker.ts, giving an error SyntaxError: Cannot use import statement outside a module. How to resolve this. ...
peaceMaker's user avatar
2 votes
1 answer
2k views

How to bundle worker_thread dependencies with webpack

I'm writing an electron application that uses electron forge for setup and configuration. The project uses Webpack 5 as a bundler and typescript as the development language. I'm having trouble running ...
Meerpohl's user avatar
  • 461
2 votes
0 answers
905 views

Worker thread immediately exits

I want to run a blocking task in a working thread to avoid blocking the event loop. I got two environments, my workstation and a server. Both have the same version of NodeJS (14.16.1). Here is a ...
Notiggsam's user avatar
2 votes
0 answers
410 views

How to .push() each worker's result into an array in node js?

I crushed onto a wall pretty violently. The thing is that I am calling a function in the main thread with the form: const {StaticPool} = require("node-worker-threads-pool"); const ...
Rodrigo Guinea's user avatar
2 votes
0 answers
2k views

nodejs worker thread shared memory

I am trying to use worker threads with the worker pool in my application which is intended to be running in a 256mb docker containers. My main thread is taking around 30mb of memory and 1 worker ...
RATTLESNAKE's user avatar
  • 3,218
2 votes
1 answer
8k views

Typescript configuration to use worker_threads

Im trying to use WebWorkers in Typescript and I have encoutered a problem. I have installed @types/node and updated everything. 'worker_threads' is not longer experimental and is in stable version of ...
Skylordis's user avatar
2 votes
1 answer
2k views

Sync worker threads in node js

I have some code for playing with "worker threads" (Node js). When in app.js in loop I set condition i<100000000, my second thread do not start before first thread not finish. How in Node js work ...
Александр Чаплыга's user avatar
2 votes
0 answers
1k views

When parallel processing in caret, verbose messages do not appear in the console

I've worked in R and a question arose. I've made up an R code using the train() function in caret library, and I also set the parallel process by registDoParallel() in doParallel. If I execute ...
Chan-ho Lee's user avatar
2 votes
2 answers
717 views

App showing doing too much work in main thread even if the operations are performed in background thread

Hi I am getting this message in log every time when execute query. But query is executing in background thread only and Table has not more 500 rows and also I always apply limit 100. Please don't ...
ImGenie's user avatar
  • 323
1 vote
0 answers
70 views

How many threads Node creates per core when using worker threads?

I'm running node js worker threads on MacBook Air M1. There are 8 core. And using PISCINA to create threads. I'm getting 12 threads. Are those for one core or on all 8 core. How do I know if main ...
C'Reality Education's user avatar
1 vote
0 answers
137 views

How to use mongo connection pool shared with worker threads

I am implementing a nodejs app where I am using worker threads for parallel data processing which requires mongo connection. I am using mongoose here for mongo operation but if I create connection in ...
rahul's user avatar
  • 536
1 vote
0 answers
224 views

Would it be possible to iterate over typescript files in a folder and start a worker thread for each using `ts-node`?

Overview How would one start a worker thread with ts-node? Every attempt that I've made leads to a MODULE_NOT_FOUND error. Various Attempts Currently, I'm attempting to spawn a new worker thread using ...
Arc's user avatar
  • 26
1 vote
0 answers
320 views

Cannot load data url in Worker Thread

My current worker thread which works fine with file path that tries to console log in that JS file: console.log("hit here"); Now I get the base64 of that file and use Data URL to replace JS ...
Kim Mỹ's user avatar
  • 388
1 vote
1 answer
1k views

Node.js- share a heavy variable from parent to worker threads

I want to share a variable between parent and worker threads. The variable is heavy (100+ MB - arrays of JSON data) so if I pass it as an argument or re-read from data source, it drastically increases ...
sprash's user avatar
  • 197
1 vote
1 answer
738 views

Node.js thread pool vs worker_thread

thread pool size can be determined with UV_THREADPOOL_SIZE. Worker_thread can create threads dynamically in runtime. Is this a only difference between thread pool and worker thread? Recently, I'm so ...
RunningLearner's user avatar
1 vote
0 answers
454 views

Multiple node processes vs multiple worker threads

I have a project which I have to convert about 300+ different small application to node. The plan is to make one linux service per application, something like: Service 1 node /le-path/le-service1.js ...
Lucas Steffen's user avatar
1 vote
0 answers
1k views

Pass data between worker threads in node js

I have a nodejs application where I need to use a worker thread. The worker thread gets a message from the main thread. The message is sent inside a function in a class. I need to pass the instance of ...
Yael Tuvia's user avatar
1 vote
0 answers
137 views

Can a SharedArrayBuffer be picked up by garbage collection in Node?

I'm trying to build a Node application using worker threads, divided into three parts. The primary thread that delegates tasks A dedicated worker thread that updates shared data A pool of worker ...
Eric N's user avatar
  • 218
1 vote
0 answers
334 views

What happens if @WorkerThread annonated function calls another function in android?

Which thread the subsequently called functions are executed? You may consider a function like the getNewsFeed() function inside the repository class given below - @Singleton class NewsFeedRepository @...
Anurag Pathak's user avatar
1 vote
0 answers
570 views

Node Worker Threads and working with TypeORM

I have a NodeJS application running TypeORM to run SQL queries. I have set up worker threads to handle some massive sql queries to avoid freezing the rest of the application while running the queries. ...
Chris Eikrem's user avatar
1 vote
0 answers
264 views

How to insert large array object in mongoose mongodb collection with the help of node worker thread?

I want to insert a large array object in a Mongoose collection with the help of node worker thread, but it is not responding. I tried it without node worker thread and it's working fine, but with ...
Satish0302's user avatar
1 vote
0 answers
1k views

Using worker thread in electron

I would like to use worker thread in my electron app. In my developer environment it is working, but after building the app with electron-builder, the javascript file that contains the worker thread ...
fricci's user avatar
  • 11
1 vote
0 answers
126 views

Boost.Fibers hosted by worker threads seem not to work – why?

I'd like to use Boost.Fibers hosted by worker threads instead of just threads. I think I've done everything as in the manual while writing the code shown below, but it seems not to work – "<...
A. Klimov's user avatar
1 vote
1 answer
2k views

nodejs worker thread has it's timeout?

I use node worker thread to run a setTimeout loop in it,but i find it is not run as my expect. Code in worker thread only run about 13 times and it stop without error. // code in nodejs worker ...
cson's user avatar
  • 47
1 vote
0 answers
59 views

Better way to have classes talk to eachother on behalf of ONE class

I really am not sure what was the best way to title this. In this example I have the following WorkerThread class class WorkerThread { public int Id; public WorkerThread(int id) { ...
Joao Vitor's user avatar
1 vote
0 answers
19 views

delegate in UI Thread update from worker (XAML)

i want to update some GUI Elements within the GUI Thread from a WorkerThread. The GUI (Class MainPage) specifies a delegate function like the following way. HRESULT MainPage::delegateUpdateGUI(...
hr1979's user avatar
  • 11
1 vote
1 answer
304 views

Slots inside QThread running concurrently

I have two classes a Handler and a Worker connected with signal and slots. Here is a simplified version (pseudo code): Handler Constructor: Handler::Handler(QObject *parent) : QObject(parent) { ...
luffy's user avatar
  • 2,326
1 vote
1 answer
113 views

Worker Thread Task completion callback not available for IntentService

As per developer guidelines, IntentService starts worker thread and destroys self. Next task is taken care by worker thread. Worker thread do not notify into IntentService that task has been ...
Sandipkumar Savani's user avatar
1 vote
1 answer
217 views

How to run long running synchronous operation in nodejs

I am writing payroll management web application in nodejs for my organisation. In many cases application shall involve cpu intensive mathematical calculation for calculating the figures and that too ...
Rahul's user avatar
  • 11
0 votes
0 answers
6 views

Node js threadworker - threadId keep increasing its threadId number

I have a worker_thread, let's say a "Thread manager" in node 18 app that is spawning, let's call them "sub-workers". They do what they do and when finished execution, they send a ...
Svetoslav Trifonov's user avatar
0 votes
0 answers
23 views

NodeJS: WorkerThread or setInterval?

I currently writing a Node app that will launch a bunch of services to check a condition every X seconds and if the result is true, will perform some actions. My first implementation is to instantiate ...
Clint's user avatar
  • 1
0 votes
0 answers
46 views

Mediapipe thread error in colab F0000 00:00:1704710377.941893 106652 threadpool_pthread_impl.cc:53] Check failed

Can someone please help me fix this issue, I am trying to use mediapipe to computer differences in facial landmarks in two different faces. The code works at first but after several steps it breaks ...
Takuphilchan's user avatar
0 votes
0 answers
19 views

How to reuse loaded tensorflow model in workerthread in nodejs

I have a tensorflowjs model that I plan to use in nodejs. As the model inference is CPU intensive, I leveraged workerthreads. I do not want to load the model to workerthread every single time before I ...
Doug's user avatar
  • 167
0 votes
0 answers
79 views

Use Piscina and Sharp libraries together for image processing in NestJS

We work on a project with NestJS and GraphQL. In the project we consider ‘image’ module to handle all images in other modules. For serving image we use Controller: @Get(':id') @Header('Cache-Control',...
Mojtaba Hassanzadeh's user avatar
0 votes
0 answers
31 views

Nodejs worker threads shared object

I have an object in the main thread. What's the best way to allow a worker thread to be able to read that object? Note that the object changes multiple times per second.
hmmmm's user avatar
  • 23
0 votes
1 answer
214 views

Worker threads in Node js

Unable to do axios calls inside worker threads Hi, I have a node js application and I am trying to use worker threads for one of my use case.Inside my worker thread I need to do axios call.I was not ...
Jay supriya miriyala's user avatar
0 votes
1 answer
151 views

worker_threads with node.js in nwjs

worker_threads with node.js in nwjs (v0.77.0) crashes without error message Here a list which versions work and where you can find the crash. It started with version v0.69.1 0.77.0 ⛔ 0.76.1 ⛔ ... 0....
Matthias Ma's user avatar
0 votes
1 answer
182 views

only one worker_threads running when i spawned two in nodejs

I have this file analyze-caption-job.ts async function analyzeCaptionJob(): Promise<void> { while (true) { console.log("analyzing!"); await new Promise(f => setTimeout(f, ...
zymeth02's user avatar
0 votes
0 answers
889 views

NodeJS Worker Threads - message sending before function finished?

I am using a pool of workers to complete some CPU intensive tasks in Node. However, I have a problem in my code below. When a task is first run, everything goes as expected, the pool is created, then ...
jlh77's user avatar
  • 66
0 votes
0 answers
278 views

Parallel processing in Node.js

I'm trying to write a node code that will read multiple json files from directory and insert mapped data into mongodb collection. In order to speed up the process, I have follwed following steps: Put ...
Sudhir's user avatar
  • 837
0 votes
0 answers
166 views

Node Worker thread is not working inside api call

I am using node version 16 and following all documented steps. Still worker thread is not working. ` const addPaymentApi = async (req) => { const { payload, adminId } = req.body; logInfo(`...
Ankit Saini's user avatar