3

Is it possible to reuse python thread object to avoid unnecessary creation of the thread? It could be useful in the following situation. There are many tasks which must be parallelized using thread pool which size is much less than the number of the tasks.

I know that there is multiprocessing.Pool, but it is very important to use threads not processes.

1

1 Answer 1

3

If you're using Python 3, the best way is definetly to use concurrent.futures.ThreadPoolExecutor.

Actually you should read the whole documentation of concurrent.futures, it's not long, and there are many great examples.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there something the same for Python 2?
@itun concurrent.futures has been backported to Py2, see pypi.python.org/pypi/futures, or you could try ThreadPool mentioned in stackoverflow.com/questions/3033952/…, I haven't used it so there's not much more I coud say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.