Here is a real world example: If you have a blocking call, like requests library, making a call to an api with a long latency, in a GUI application. When making the call the GUI locks up until requests returns. If you run the call to requests in a separate thread, the GUI is not locked. Answer from ElliotDG on reddit.com
🌐
Python
docs.python.org › 3 › library › threading.html
threading — Thread-based parallelism — Python 3.14.4 ...
Python’s Thread class supports a subset of the behavior of Java’s Thread class; currently, there are no priorities, no thread groups, and threads cannot be destroyed, stopped, suspended, resumed, or interrupted.
🌐
Real Python
realpython.com › intro-to-python-threading
An Intro to Threading in Python – Real Python
August 5, 2024 - A thread is a separate flow of execution. This means that your program will have two things happening at once. But for most Python 3 implementations the different threads do not actually execute at the same time: they merely appear to.
Discussions

is there any reason to use thread in python?
Here is a real world example: If you have a blocking call, like requests library, making a call to an api with a long latency, in a GUI application. When making the call the GUI locks up until requests returns. If you run the call to requests in a separate thread, the GUI is not locked. More on reddit.com
🌐 r/learnpython
24
21
October 11, 2023
multithreading - How do I use threading in Python? - Stack Overflow
I would like a clear example showing tasks being divided across multiple threads. More on stackoverflow.com
🌐 stackoverflow.com
Why use threads in Python?
Numeric libraries (numpy, numba) tend to 'release' the Gil, meaning multiple threads can meaningfully used for speedups More on reddit.com
🌐 r/Python
54
65
April 8, 2018
Multi-Threading in Python

New to programming and immediately diving into multithreading? Do you have a specific problem to solve? Not saying we won't help you, but it seems like you're starting on the wrong things.

More on reddit.com
🌐 r/learnpython
26
7
September 14, 2021
🌐
W3Schools
w3schools.com › python › ref_module_threading.asp
Python threading Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... import threading def task(): print('Thread running for Linus') thread = threading.Thread(target=task) print(f'Thread created: {thread.name}') Try it Yourself »
🌐
Reddit
reddit.com › r/learnpython › is there any reason to use thread in python?
r/learnpython on Reddit: is there any reason to use thread in python?
October 11, 2023 -

after learning more about asyncio (for IO bound) and multiprocessing (for CPU bound), I start to wonder if there is any real life use case for threading in python. It seems python threading comes with its own baggage, like GIL lock, and it was mentioned that python threading, is not really really multi-thread since due to limitation on interpreters' binding to CPU, only a thread could be scheduled at a time?

This makes me wonder why we even want to use python thread at all?

Top answer
1 of 9
18
Here is a real world example: If you have a blocking call, like requests library, making a call to an api with a long latency, in a GUI application. When making the call the GUI locks up until requests returns. If you run the call to requests in a separate thread, the GUI is not locked.
2 of 9
9
Threading is absolutely not legacy and both threading and asyncio have their place. Asyncio and threading work similarly at the high level but don't work the same at the low level. At the low level threads are still managed by the operating system, where asyncio tasks are managed with a Python event loop. With threading the OS can change threads at ANY time during execution, so you have to be more careful about how data is accessed. With asyncio you choose when work between tasks can change. Asyncio is great for LOTS of tasks, especially since it has less overhead. Threading has more overhead and having lots of threads can start to slow things down more than it speeds up. One of the subtle issues with asyncio is if a task gets hung up or doesn't play nice it can prevent all your other tasks from running. For critical tasks that absolutely must keep running threading is better. For example I often write interfaces that receive critical telemetry from something over a UDP port. The front end consists of a thread that receives data on the UDP socket then logs it and puts it in a queue. Another processing thread then pulls the data from the queue to process it. The receiving and logging is super critical. If the processing thread dies or gets hung up it's not a huge deal as long as the data is still being received and logged.
🌐
GeeksforGeeks
geeksforgeeks.org › python › multithreading-python-set-1
Multithreading in Python - GeeksforGeeks
October 3, 2025 - Multithreading in Python allows multiple threads (smaller units of a process) to run concurrently, enabling efficient multitasking.
🌐
Site24x7
site24x7.com › learn › threading-in-python.html
Threading in Python: A Complete Guide - Site24x7
All synchronization primitives that the Threading module provides can be expressed using the “with” statement syntax. “with” is a form of “Resource Acquisition Is Initialization” (RAII), a principle used to manage resources in a way that automatically releases them when they go out of scope. By using the “with” statement, you can prevent potential deadlocks and enhance the readability and maintainability of your code. ... The “concurrent.futures” module in Python offers a “ThreadPoolExecutor” class, which allows developers to create and manage thread pools for handling asynchronous tasks.
🌐
Codecademy
codecademy.com › docs › python › threading
Python | Threading | Codecademy
April 21, 2025 - The threading module allows multiple threads of execution to take place in a Python program.
Find elsewhere
Top answer
1 of 16
1660

Since this question was asked in 2010, there has been real simplification in how to do simple multithreading with Python with map and pool.

The code below comes from an article/blog post that you should definitely check out (no affiliation) - Parallelism in one line: A Better Model for Day to Day Threading Tasks. I'll summarize below - it ends up being just a few lines of code:

from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool(4)
results = pool.map(my_function, my_array)

Which is the multithreaded version of:

results = []
for item in my_array:
    results.append(my_function(item))

Description

Map is a cool little function, and the key to easily injecting parallelism into your Python code. For those unfamiliar, map is something lifted from functional languages like Lisp. It is a function which maps another function over a sequence.

Map handles the iteration over the sequence for us, applies the function, and stores all of the results in a handy list at the end.


Implementation

Parallel versions of the map function are provided by two libraries:multiprocessing, and also its little known, but equally fantastic step child:multiprocessing.dummy.

multiprocessing.dummy is exactly the same as multiprocessing module, but uses threads instead (an important distinction - use multiple processes for CPU-intensive tasks; threads for (and during) I/O):

multiprocessing.dummy replicates the API of multiprocessing, but is no more than a wrapper around the threading module.

import urllib2
from multiprocessing.dummy import Pool as ThreadPool

urls = [
  'http://www.python.org',
  'http://www.python.org/about/',
  'http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html',
  'http://www.python.org/doc/',
  'http://www.python.org/download/',
  'http://www.python.org/getit/',
  'http://www.python.org/community/',
  'https://wiki.python.org/moin/',
]

# Make the Pool of workers
pool = ThreadPool(4)

# Open the URLs in their own threads
# and return the results
results = pool.map(urllib2.urlopen, urls)

# Close the pool and wait for the work to finish
pool.close()
pool.join()

And the timing results:

Single thread:   14.4 seconds
       4 Pool:   3.1 seconds
       8 Pool:   1.4 seconds
      13 Pool:   1.3 seconds

Passing multiple arguments (works like this only in Python 3.3 and later):

To pass multiple arrays:

results = pool.starmap(function, zip(list_a, list_b))

Or to pass a constant and an array:

results = pool.starmap(function, zip(itertools.repeat(constant), list_a))

If you are using an earlier version of Python, you can pass multiple arguments via this workaround).

(Thanks to user136036 for the helpful comment.)

2 of 16
769

Here's a simple example: you need to try a few alternative URLs and return the contents of the first one to respond.

import Queue
import threading
import urllib2

# Called by each thread
def get_url(q, url):
    q.put(urllib2.urlopen(url).read())

theurls = ["http://google.com", "http://yahoo.com"]

q = Queue.Queue()

for u in theurls:
    t = threading.Thread(target=get_url, args = (q,u))
    t.daemon = True
    t.start()

s = q.get()
print s

This is a case where threading is used as a simple optimization: each subthread is waiting for a URL to resolve and respond, to put its contents on the queue; each thread is a daemon (won't keep the process up if the main thread ends -- that's more common than not); the main thread starts all subthreads, does a get on the queue to wait until one of them has done a put, then emits the results and terminates (which takes down any subthreads that might still be running, since they're daemon threads).

Proper use of threads in Python is invariably connected to I/O operations (since CPython doesn't use multiple cores to run CPU-bound tasks anyway, the only reason for threading is not blocking the process while there's a wait for some I/O). Queues are almost invariably the best way to farm out work to threads and/or collect the work's results, by the way, and they're intrinsically threadsafe, so they save you from worrying about locks, conditions, events, semaphores, and other inter-thread coordination/communication concepts.

🌐
Tutorialspoint
tutorialspoint.com › python › python_multithreading.htm
Python - Multithreading
In Python, multithreading allows you to run multiple threads concurrently within a single process, which is also known as thread-based parallelism. This means a program can perform multiple tasks at the same time, enhancing its efficiency and
🌐
Codecademy
codecademy.com › docs › python › threading › .thread()
Python | Threading | .Thread() | Codecademy
April 22, 2025 - The .Thread() constructor from Python’s threading module creates a thread object that can run a specified function with optional arguments.
🌐
Python documentation
docs.python.org › 3 › howto › free-threading-python.html
Python support for free threading — Python 3.14.4 documentation
Starting with the 3.13 release, CPython has support for a build of Python called free threading where the global interpreter lock (GIL) is disabled. Free-threaded execution allows for full utilization of the available processing power by running threads in parallel on available CPU cores.
🌐
Py-free-threading
py-free-threading.github.io
Python Free-Threading Guide
Free-threaded CPython is here! This website serves as a centralized resource for Python package maintainers, as well as end users, interested in supporting or experimenting with free-threaded Python.
🌐
Python Module of the Week
pymotw.com › 2 › threading
threading – Manage concurrent threads - Python Module of the Week
Now available for Python 3! Buy the book! ... The threading module builds on the low-level features of thread to make working with threads even easier and more pythonic.
🌐
StrataScratch
stratascratch.com › blog › python-threading-like-a-pro
Python Threading Like a Pro - StrataScratch
September 6, 2023 - The concurrent execution of more ... use its pet name. In the context of Python, threading is a built-in module that allows various threads to execute concurrently....
🌐
Mimo
mimo.org › glossary › python › multithreading
Mimo: The coding platform you need to learn Web Development, Python, and more.
Python multithreading allows you to run multiple threads in parallel within a single process. This is especially useful for I/O-bound tasks like handling multiple web requests, reading files, or making API calls. Python’s threading module makes it easy to create and manage threads for concurrent execution...
🌐
Python 101
python101.pythonlibrary.org › chapter21_thread.html
Chapter 21 - The threading module — Python 101 1.0 documentation
So in this example, we will create a Thread class that can download files from the internet. The U.S. Internal Revenue Service has lots of PDF forms that it has its citizens use for taxes. We will use this free resource for our demo. Here’s the code: # Python 2 version import os import urllib2 from threading import Thread class DownloadThread(Thread): """ A threading example that can download a file """ def __init__(self, url, name): """Initialize the thread""" Thread.__init__(self) self.name = name self.url = url def run(self): """Run the thread""" handle = urllib2.urlopen(self.url) fname =
🌐
InfoWorld
infoworld.com › home › software development › programming languages › python
Python threading and subprocesses explained | InfoWorld
May 29, 2025 - Python threads are units of work that run independently of one another. In CPython, they’re implemented as actual operating system-level threads, but they’re serialized—meaning they’re forced to run serially—through the GIL.
🌐
Python Tutorial
pythontutorial.net › home › python concurrency › python threading
A Practical Guide to Python Threading By Examples
June 4, 2023 - The task 10 completed The task 8 completed The task 1 completed The task 6 completed The task 7 completed The task 9 completed The task 3 completed The task 4 completed The task 2 completed The task 5 completed It took 1.02 second(s) to complete.Code language: Python (python) It just took 1.05 seconds to complete. Notice that the program doesn’t execute the thread in the order from 1 to 10.
🌐
DEV Community
dev.to › imsushant12 › multithreading-in-python-lifecycle-locks-and-thread-pools-3pg3
Multithreading in Python: Lifecycle, Locks, and Thread Pools - DEV Community
October 13, 2025 - Thread 4 entered Thread 4 exited. ... If no value is specified in the Semaphore object (for example, obj = Semaphore()), then it behaves like a lock. Python also provides BoundedSemaphore, which is similar to Semaphore but adds a safety check, i.e., if a thread calls release() more times than acquire(), it will raise a ValueError.