Giter Site home page Giter Site logo

Pool#join not working ? about ruby-thread HOT 11 CLOSED

meh avatar meh commented on August 28, 2024
Pool#join not working ?

from ruby-thread.

Comments (11)

meh avatar meh commented on August 28, 2024

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.

meh avatar meh commented on August 28, 2024

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.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

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.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

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.

meh avatar meh commented on August 28, 2024

#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.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

OK. I'll have a go. I'll let you know when I'm done.

from ruby-thread.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

BTW. Do you agree that the @trim_requests -= 1 is a bug? Or am I mistaken?

from ruby-thread.

meh avatar meh commented on August 28, 2024

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.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

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.

Kris-LIBIS avatar Kris-LIBIS commented on August 28, 2024

Auto_trim did not work for me unless I changed that line to += ...

from ruby-thread.

meh avatar meh commented on August 28, 2024

Oh, yeah, I'm sorry, you're right, I was looking in the worker instead of #trim.

from ruby-thread.

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.