from concurrent.futures import ThreadPoolExecutor with ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(pow, 323, 1235) print(future.result())
import multiprocessing from concurrent.futures import ProcessPoolExecutor
import time
defdo(file_name, i, lock): with lock: withopen(file_name, 'a+') as f: f.writelines(["i=" + str(i) + ":" + str(x) + "\n"for x inrange(3)])
defmain(): pool = ProcessPoolExecutor(max_workers=4) m = multiprocessing.Manager() lock = m.Lock() futures = [pool.submit(do, "./test.txt", num, lock) for num inrange(3)] for future in futures: future.result()