Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 982819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:45:33+00:00 2026-05-16T04:45:33+00:00

I need to use a thread pool in python, and I want to be

  • 0

I need to use a thread pool in python, and I want to be able to know when at least 1 thead out or “maximum threads allowed” has finished, so I can start it again if I still need to do something.

I has been using something like this:

def doSomethingWith(dataforthread):
    dostuff()
    i = i-1 #thread has finished

i = 0
poolSize = 5
threads = []
data = #array of data
while len(data):
    while True:
        if i<poolSize: #if started threads is < poolSize start new thread
            dataforthread = data.pop(0)
            i = i+1
            thread = doSomethingWith(dataforthread)
            thread.start()
            threads.append(thread)
        else:
            break
    for t in threads: #wait for ALL threads (I ONLY WANT TO WAIT FOR 1 [any])
        t.join()

As I understand, my code opens 5 threads, and then waits for all the threads to finish before starting new threads, until data is consumed. But what I really want to do is start a new thread as soon as one of the threads finish and the pool has an “available spot” for a new thread.

I have been reading this, but I think that would have the same issue than my code (not sure, im new to python but by looking at joinAll() it looks like that).

Does someone has an example to do what I am trying to achieve?

I mean detecting as soon as i is < than poolSize, launching new threads until i=poolSize and do that until data is consumed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:45:34+00:00Added an answer on May 16, 2026 at 4:45 am

    As the article author mentions, and @getekha highlights, thread pools in Python don’t accomplish exactly the same thing as they do in other languages. If you need parallelism, you should look into the multiprocessing module. Among other things, it has these handy Queue and Pool constructs. Also, there’s an accepted PEP for “futures” that you’ll probably want to monitor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First convert to PDF the complete file with whatever tool… May 16, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer You might want to take a look here. To summarize… May 16, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer To do this generically, you could use something like the… May 16, 2026 at 5:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write a simple thread pool program in pthread. However, it seems
When using a thread pool and its queuecallbackitem, can I not pass in a
It seems to be impossible to make a cached thread pool with a limit
I have a simple thread pool written in pthreads implemented using a pool of
I want a timer tick/elapsed event inside a new thread. It seems like I
I’m looking for the best way of using threads considering scalability and performance. In
Hi guys I need to implement a way to timeout my objects without using
We need to read and count different types of messages/run some statistics on a
I've written a Windows program in C++ which at times uses two threads: one
I use Zend Server CE on my Mac running OSX Snow Leopard for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.