-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1 Pool issue / usage issue #108
Comments
Thanks for reporting, @aarmora. Moved your comment into this issue here, since it's quite complex 😉 I think it's more of a usability issue. Might be worth reviewing the API, though, if it's confusing to use. Considering your code: You only call If you have a suggestion how to make the usage clearer, feel free to suggest a change. |
@andywer Good feedback. If that's the issue, then that totally makes sense and then I just think only the documentation is the issue showing more than one item being queued. I can submit a PR for that once I fully understand how it works. I tried to implement it how I would expect it per your explanation; queueing three tasks when my pool is set to 2 and I get similar results. It hits Maybe this is due to how these are promises and I'm not awaiting for them until below so the queue thinks it's finished before the task is actually finished. This doesn't match exactly what the event queue is returning since it does |
@andywer But actually... isn't my loop calling |
Yeah, the out-commented There is one thing that's odd, though. It should rather be like this: - await pool.queue(async looper => {
- promises.push(looper(/* ... */))
- })
+ promises.push(pool.queue(async looper => {
+ await looper(/* ... */)
+ })) Not sure how much of a difference it makes in practice, though. IdeaThere should be a convenience method to wait until the pool has completed all pending jobs. How about something like this? for (/* ... */) {
pool.queue(looper => looper(/* ... */))
}
await pool.completed() |
The order of the console output is strange indeed. Got to investigate. Maybe the console output of master and worker thread is not guaranteed to be printed in order. |
@andywer I am actually intentionally not |
Sorry, I had one typo in the first for-loop example - of course you don’t want to await the pool.queue(). Look at what I outlined under "Idea". It's really just a convenient way to not have to promises.push() manually 😉 |
@andywer Yes, having a |
Try the latest alpha version: You can now use call Let me know if that solves the issue for you. Haven't investigated the strange log output yet, though. You can also try to set the environment variable |
Btw, do you still have issues using the lib with node < 12? |
@andywer I just tried with node 10 and I still get the following error: |
@andywer alpha.4 worked GREAT with Check my test code. import { spawn, Thread, Worker, Pool } from 'threads';
The blocks log out as expected when they hit the exposed looper function, matching the pool limit I put on it. |
Cool! 🙌
I think I have a rough idea why it's failing. It's due to Windows: It seems to interpret some path I don't have a Windows machine at hand... Could you add some |
It appears to be at It also doesn't appear to be breaking all the time, oddly enough. Here's what my file looks like and then the terminal output. You can see in the terminal it hits both before and after the Hope this helps. |
Hmmm, I think we also need to log what `obj' is before shit hits the fan... |
Thanks, man! I think I finally found the corresponding issue in the node repo: nodejs/node#15374 What node version do you use? Is it an up-to-date node 10.x? Anyway, we should be able to work around this issue by making the absolute path relative again on Windows. |
PS: Can you try changing the code in tiny-worker's worker.js to:
|
@aarmora Can you maybe checkout the branch The tests fail with a timeout error in Travis CI on a Windows runner, but I am not sure if an error occurs that is not shown or if it's actually running into a timeout... |
@andywer I am testing on Node v10.16.0. Changing to
If I adjust the worker path to
I'm not familiar with path.relative and so without digging into it, it looks like I need another slash in there somewhere. |
@andywer Running the tests on |
Cool and thanks a lot! Let's try running the tests again with a 30s timeout then, shall we? 😅🙈 It's ridiculous that it takes so long to spawn a new process with |
@andywer Woo!! Nice! :D |
As originally reported by @aarmora in #100:
Hey @andywer! I decided to turn my constant twitter barrage into official stuff here. I'm loving v1 and I have been messing with Pool today. The events logged say that the size is 2 in my case but I don't seem to see any queueing.
I would have expected it to show two blocks of
all the items
, output the numbers looped through for those two arrays, and then two more blocks ofall the items
. Instead it looks like it's running everything immediately.Example code:
Image Example:
The text was updated successfully, but these errors were encountered: