I'm using Python's concurrent.futures framework. I have used the map()
function to launch concurrent tasks as such:
def func(i):
return i*i
list = [1,2,3,4,5]
async_executor = concurrent.futures.ThreadPoolExecutor(5)
results = async_executor.map(func,list)
I am interested only in the first n
results and want to stop the executor after the first n
threads are finished where n
is a number less than the size of the input list. Is there any way to do this in Python? Is there another framework I should look into?