How to start all the threads simultaneously using ThreadPoolExecuter in Python?

Viewed 36

I've written the following code to start 1000 threads simultaneously, but It seems that when I call submit() on each iteration, that thread starts and this makes a big time difference between the starting time of the first and the last thread. I wonder if there is a way to just save threads in ThreadPoolExecuter and run all of them simultaneously after the for loop?

with concurrent.futures.ThreadPoolExecuter(max_workers=1000) as executer:
    for i in range(1000):
        executer.submit(foo, i)
0 Answers
Related