ThreadPools in Python 2.x

Python 2.x frameworks doesn’t come with any thread pool by default but an handy library is provided by Chris A. You can anyway easily install it with
pip install threadpool on any OS which supports pip.
You can read more about threadpool library at this address:

Here below you can have a look at how to use it in a simple way.

import time
from threadpool import ThreadPool, makeRequests

def worker(a):
“””thread worker function”””
print ‘Worker start’
for x in xrange(10000000):
print ‘Worker stop’

requests = makeRequests(worker, data)
[pool.putRequest(req) for req in requests]

print “all thread finished”
# wait for 1s would be enough to get threads cleaned

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.