Skip to content
UPEEC

Multithreading

threading runs functions concurrently in one process — good for I/O-bound tasks.

Intermediate
Comments 0
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=8) as pool:
    pages = list(pool.map(download, urls))

Protect shared data with threading.Lock; prefer queues for passing work between threads.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.