Can I limit ThreadPoolExecutor to use only 1 processor core, 1 process and 1 thread at the same time but run a function asynchronously?
import time, concurrent.futures def ts(start): return round(time.perf_counter() - start, 3) def fn(sec): print(f'{ts(start)}\tstart sleeping {sec}') time.sleep(sec) def main(): lst = [1, 1, 1, 1, 1, 1] with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor: executor.map(fn, lst) start = time.perf_counter() if __name__ == "__main__": main() print(f'{ts(start)}\tfinish') # 0.001 start sleeping 1 # 1.008 start sleeping 1 # 2.01 start sleeping 1 # 3.021 start sleeping 1 # 4.024 start sleeping 1 # 5.038 start sleeping 1 # 6.051 finish I'd like to run all the functions successively but instead of waiting the result after each run, wait all the results at the end like this:
# 0.001 start sleeping 1 # 0.002 start sleeping 1 # 0.003 start sleeping 1 # 0.004 start sleeping 1 # 0.005 start sleeping 1 # 0.006 start sleeping 1 # 1.051 finish