---
title: 'Python Threading Explained in 8 Minutes'
source: 'https://youtube.com/watch?v=A_Z1lgZLSNc'
video_id: 'A_Z1lgZLSNc'
date: 2026-06-18
duration_sec: 0
---

# Python Threading Explained in 8 Minutes

> Source: [Python Threading Explained in 8 Minutes](https://youtube.com/watch?v=A_Z1lgZLSNc)

## Summary

This video explains multi-threading in Python using the `threading` module. It clarifies that due to the Global Interpreter Lock (GIL), Python's threading is pseudo-concurrent, switching between tasks during I/O waits. The tutorial demonstrates creating and managing threads with a simple worker function that prints a counter until a user quits.

### Key Points

- **Introduction to Python Threading** [0:00] — The video covers multi-threading in Python simply and quickly.
- **No True Multi-threading in CPython** [0:16] — Due to the Global Interpreter Lock (GIL), Python uses pseudo multi-threading, switching between tasks during downtime (e.g., waiting for I/O, user input, or sleep).
- **Importing Modules** [1:08] — Use `import threading` (core module) and `import time` for the `sleep` function to create downtime.
- **Defining a Worker Function** [1:32] — A `worker` function is defined with a loop that increments a counter and prints it every second, controlled by a global `done` flag.
- **Running Without Threading** [2:27] — Running the worker function in the main thread blocks execution, preventing user input handling until the loop ends.
- **Creating a Thread** [3:41] — Use `threading.Thread(target=worker).start()` to run the worker function in a separate thread, allowing simultaneous user input.
- **Daemon Threads** [4:53] — Set `daemon=True` to make a thread a daemon thread, which allows the script to exit even if the thread is still running, as it runs in the background.
- **Passing Arguments to Threads** [5:36] — Use `args=(value,)` to pass arguments to the target function. Multiple threads can run the same function with different arguments.
- **Joining Threads** [7:22] — Use `thread.join()` to wait for a thread to finish before continuing execution in the main thread.

### Conclusion

Python's threading module enables concurrent execution by switching tasks during I/O waits, but true parallelism is limited by the GIL. The tutorial provides a practical example of creating, starting, and managing threads, including daemon threads and joining.

## Transcript

what is going on guys welcome back in
this video today we're going to cover
multi-threading in python as simply and
as quickly as possible so let us get
right into it it's not a g it's
[Music]
AED all right now one thing that I want
to mention right away is that there is
no actual multi-threading in Python at
least not in the most commonly used
cpython implementation that you're
probably running on your system because
of something called the global interpret
to lock and we're not going to go into
too much detail here but what this
essentially means is that we have some
sort of pseudo multi-threading where we
do stuff concurrently and somewhat at
the same time but what's actually
happening is that we're switching
between the tasks and we're using the
down times of the different tasks to
execute the other tasks so for example
we send a request we wait for a response
that is some doubt time or we're waiting
for user input that is some downtime or
we're just sleeping with time dos sleep
that is also some downtime and this can
be used for execution of other tasks and
this is what the threading module
actually does and this is just the
theoretical background here in order to
work with multi-threading and python
with the pseudo multi-threading in
Python what you need to do is you need
to say import threading uh this is a
core python module we don't need to
install anything for that uh and in
addition to that we're going to also
import time which is going to allow us
to use the mentioned sleep function to
create some downtime and we're going to
do a very simple example here to
understand the concept of threading in
python or for multi-threading in Python
what we're going to do is we're going to
define a function we're going to call it
worker because it's going to be our
worker function and this function will
do something quite simple we're going to
Define a variable up here done we're
going to set it to false and inside of
our worker function we're going to have
a loop while not done so basically an
endless loop until this thing is set to
True while not done we're going to say
uh time do sleep wait 1 second sleep 1
second basically and then we're going to
print some counter we're going to first
of all Define a counter up here being
equal to zero we're going to say that
the counter is going to be increased by
one with each
iteration and we're going to print the
counter this is what we want to do here
nothing too fancy just a simple function
that constantly prints 1 2 3 4 until we
set done to true so without using any
threading stuff here let's just run this
function and see what happens this is
going to be then running in the main
thread and you can see it just prints 1
2 3 4 5 and so on um now what we want to
do here is we want to in addition to
that function also process some user
input so in the main thread for example
we want to wait for the user to input
something or to just press enter now how
would we do that we would do something
like while not
done we want to say uh wait for the user
input so press PR enter to quit for
example or actually we don't need to
Loop here we can just wait for the input
statement here and after the input
statement is over so after the user
presses uh enter we can just set done to
true so the goal is to have this
function running counting from uh 1 to
two to three to four and so on until we
press enter to quit that the problem is
however now that um this is running in
the main thread and this comes after dys
function so we will not get to that
statement uh unless this function
finishes with the work so unless this
function breaks out of the loop and we
can continue with the rest of the code
if we want to have both things running
simultaneously we will have to do
multi-threading and this is done the
following way we used the threading
module to define a thread by saying
threading do thread and then we can
specify a Target function so Target
equals and we can pass the worker
function here as an object passing it as
an object means not passing it with the
parenthesis so not calling it but just
uh passing the instance of worker just
passing the object worker which is the
function The Entity worker um and then
this is the object this is the actual
threat we can either store it in a
variable and then start the variable or
we can start it right away like this by
setting saying threading do thread
Target equals worker. start and this is
going to now start the worker function
in a separate thread so if I run this um
you will be able to see press enter to
quit 1 2 3 I'm not pressing anything if
I now press enter it goes past the
statement and it sets done to true and
since done is set to true this also
terminates this worker now this would
not work of course if I have here an
endless loop while true then even if I
press enter it's not going to quit
because then uh the main thread doesn't
have anything to do but this threat is
still running however we can also change
that by saying that this threat is not
an important threat we don't want to
keep the program running if everything
else has finished finished this is a
so-called Damon threat which basically
means if nothing else is running you can
also quit the script even though this
threat is running we can specify here
Damon equals true and this basically
means what I just said that this is
running in the background and as soon as
the main threat and the other important
threats have finished we can also quit
the script we don't have to wait for
this particular threat here because it's
just a Damon threat so I can run this
now and I can press enter And even
though this enter doesn't change
anything about this Loop even though
this threat is still running we're just
terminating the whole script because
this is just a Damon threat that is what
this is for we can also pass arguments
by just passing text here for example
and saying that we want to print an F
string with text and then the counter
just making up some stuff here uh we can
do that by passing arguments so we can
say arcs equals and we can pass a tupal
of arguments here and in this case we're
going to just pass ABC but since this is
a tupal we need need to also pass a
comma otherwise this is just going to be
treated as a single value but we need a
tuple uh we can do the same thing we can
run another thread with the same
function XYZ here as a text and you're
going to see what this actually does you
can see that it uh prints ABC counter oh
actually I just noticed that we're uh
printing counter we need of course to
print the actual value of counter you
can see here now abc1 xyz1 uh how these
are running in parallel and if I press
enter since both of them are Damon
threats we are quitting the script if I
set now one of them not to a Damon
threat and the other one uh to a Damon
threat uh you will see that if I just
press enter now one of them is going to
stop um
actually doesn't stop any of those oh of
course sorry this was uh this was not a
correct thought because since one of
them is running the other one is going
to run as well because if we set one of
them to not a Damon thread this is still
an important thread and because the
script is not finished because there is
some threat still running the Damon
threat is going to run as well um so
setting one of them to false to not
being a Damon threat keeps all of them
running because Damon doesn't mean that
you're just quitting it but it just
means that since something is still
running we're going to keep this running
as well but if nothing else is running
we're going to uh not keep this running
anymore and the last thing I want to
show you here I'm not going to show you
here as a demonstration but just as a
concept is if you have a list of mult
multiple threats if you say for example
this is T1 and this is T2 and you don't
call the start but you just save them as
objects here and then you do T1 start
and T2 start this is the same
functionality here you can also wait for
those threats so if you do something and
you don't want to continue with this
here until both threats have finished
with the execution then you can say t1.
jooin and t2. jooin and you would not
get to this code section here um until
the threats have finished so you can see
it doesn't even print press enter to
quit because it doesn't get to that line
since both threats are still running so
that's it for today's video I hope you
enjoyed it and hope you learned
something if so let me know by hitting a
like button and leaving a comment in the
comment section down below and of course
don't forget to subscribe to this
Channel and hit the notification Bell to
not miss a single future video for free
other than that thank you much for
watching see you in the next video and
bye
[Music]
