Startonix / Modular-AI

Advanced AI Training and Building Repository
0 stars 0 forks source link

Multithreading and Multiprocessing #161

Open Startonix opened 5 months ago

Startonix commented 5 months ago

multithreading_example.py

import concurrent.futures

def io_bound_task(file): with open(file, 'r') as f: return f.read()

files = ['file1.txt', 'file2.txt', 'file3.txt'] with concurrent.futures.ThreadPoolExecutor() as executor: results = list(executor.map(io_bound_task, files)) print(results)