import concurrent.futures
import time
def process_one(i):
try:
print("dealing with {}".format(i))
time.sleep(50)
print("{} Done.".format(i))
except Exception as e:
print(e)
def process_many():
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
executor.map(process_one,
range(100),
timeout=3)
if __name__ == '__main__':
MAX_WORKERS = 10
try:
process_many()
except Exception as e:
print(e)
The docs say:
The returned iterator raises a
concurrent.futures.TimeoutError
if__next__()
is called and the result isn’t available aftertimeout
seconds from the original call toExecutor.map()
But here the script didn't raise any exception and kept waiting. Any suggestions?