Python 提供三种并发模型,选择正确的模型主要取决于你的工作是 I/O 密集型 还是 CPU 密集型 — 这个决定在很大程度上由 GIL 影响(GIL 阻止线程并行运行 Python 代码)。
三种模型
text
threading → multiple threads, ONE process. GIL-limited for CPU.
multiprocessing → multiple PROCESSES, each its own interpreter/GIL → true parallelism.
asyncio → single thread, cooperative coroutines yielding at await points.
threading — 用于 I/O 密集型并发
python
concurrent.futures ThreadPoolExecutor
ThreadPoolExecutor(max_workers=) ex:
results = (ex.(download_url, urls))
