p = ThreadPool(processes=10) # creates a pool of 10 workers
p.map(function_to_call, iterable) # calls FUNCTION_TO_CALL with the first item from iterable as parameter
p.close() # closes the multi-threaded processes one all threads done
I've been trying to use this model, but what if I want to thread a function which has no parameters. Like run() . What would I put for the 'iterable' space, I've been looking all around and can't find a solution.
The Pool.apply
function is what you are looking for. Use Pool.apply_async
if you want a non blocking call.
p = ThreadPool(processes=10)
p.apply(function_to_call)
p.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With