import sys import os import concurrent.futures def load(path): if not os.path.exists(path): print(f"Error: {os.path.abspath(path)} does not exist.") sys.exit(1) print("Reading file...") with open(path) as file: text = file.read() return text txt = load("file.txt") # Ensuring file was loaded in case of some lazy-handling print(f"Text loaded was: '{txt}'") os.makedirs("test_dir", exist_ok=True) os.chdir('test_dir') futures = [] with concurrent.futures.ProcessPoolExecutor(5) as executor: for i in range(5): futures.append(executor.submit(print, txt)) concurrent.futures.wait(futures)