Comments (11)
Yeah, that solution is unacceptable, I know about the issue on MRI, it's a bug in the deadlock inference, I opened a bug on Ruby's issue tracker but I was unable to come up with a reduced testcase, so they ignored it.
I'll try to find a proper solution, but it really isn't easy, pools are supposed to be used in long running applications rather than to achieve parallelization in simple scripts.
from ruby-thread.
No wait, now that I think of it, you should use #shutdown
and not #join
there, the pool is never going to be closed if you join.
I think I should make #join
private, or work differently, as in "wait for all the tasks to be consumed", what do you think?
from ruby-thread.
The wait for all the tasks to be consumed is actually what I wanted to achieve.
I have a batches of workload that comes in at irregular times. Each batch should be handled in different stages. I need to be sure that a batch has finished stage 1 completely before I start with stage 2. Then stage 3 and so on. When the batch is completely processed, it will wait for the next batch.
I want to use the same Pool for stage 1, stage 2, stage 3, .... which is why I cannot call shutdown. Actually, I wanted to have 4 threads minimum with a max of up to 20 threads, but - of course - any minimum not 0 does not work with join.
I'm actually wondering what the join method is supposed to do, currently? AFAIK it will just hang. I replaced worker.join with a simple sleep(0.3) and trim and that works just as well. worker.join seems to never return.
from ruby-thread.
I've forked the code and trying to implement a wait that returns when (@todo.empty? and @waiting == @Spawned). That should do the trick, not?
from ruby-thread.
#join
right now is useful if you call #shutdown!
and want to wait for the workers to end and it's used internally by #shutdown
.
So yes, it's kind of useless and not what you want as is.
I think the best way to go is to merge the current #join
in #shutdown
and make #join
wait for the current tasks to finish.
Depending on how you implement the waiting, having @todo.empty? && @waiting == @spawned
should be a good check.
from ruby-thread.
OK. I'll have a go. I'll let you know when I'm done.
from ruby-thread.
BTW. Do you agree that the @trim_requests -= 1 is a bug? Or am I mistaken?
from ruby-thread.
You're mistaken, the number of trim requests is decreased when one of the workers is closed, if you increment it all the workers will die.
from ruby-thread.
Are you sure? I was talking about the line in the #trim method. Shouldn't the trim_requests go up when a new trim request is made?
from ruby-thread.
Auto_trim did not work for me unless I changed that line to += ...
from ruby-thread.
Oh, yeah, I'm sorry, you're right, I was looking in the worker instead of #trim
.
from ruby-thread.
Related Issues (20)
- rescuing Exception in pool.rb HOT 1
- memory leak in Thread::Future HOT 1
- pool.join throws HOT 3
- pool#wait_done exits prematurely HOT 1
- Would tagging releases be possible? HOT 3
- [v0.1.6] Thread dies immediately. HOT 3
- Cannot shutdown thread pool HOT 2
- [v 0.1.6] ThreadError: deadlock; recursive locking HOT 2
- Cannot run methods in pool.process block? HOT 6
- `Thread::Pool::Task` leaks HOT 19
- Exception raised when cancelling future in a pool queue. HOT 3
- A little bit of usage help HOT 5
- Thread pool wait HOT 2
- Should pipe act like an enumerable? HOT 4
- Thread skip or break HOT 3
- Synchronizing writes across threads HOT 4
- exceptions in threads HOT 3
- Following example not worked. HOT 4
- Incorrect comment for Thread::Pool::Task#terminate!
- Use CLOCK_MONOTONIC instead of Time.now
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 ruby-thread.