I have the following example:
import time
import concurrent.futures
x = [10, 1, 2]
def sleeper(secs):
time.sleep(secs)
print('I slept for {} seconds'.format(secs))
# returns in the order given
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
for future in executor.map(sleeper, x):
future
I would expect that this function will print "I slept for {} seconds" in order that of each sleeping, however, ALL the results are printed after the last value (10) is processed.
Why is this occurring and how would I print sleeper as each call completes