My code
import time
from multiprocessing.pool import ThreadPool
from concurrent.futures import ThreadPoolExecutor
def print_function(tests):
while True:
print tests
time.sleep(2)
executor = ThreadPoolExecutor(max_workers=2)
for i in range(5):
a = executor.submit(print_function(i))
output
0 0 0 0 0 0 0 0...
but I want out 012345, 012345, 012345...
How can I do this ?
executor
do that for you. Did you mean:a = executor.submit(print_function, i)
?time.sleep
will not be sufficient to keep blocks coherent and you might get "0341205". Basically if you want such order, then threading/multiprocessing is very, very likely the wrong tool.