Open Startonix opened 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)
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)