uh hello guys welcome to this video so
in this video I will show you a Python
package by which you can implement
multi-threading or parallel execution of
multiple functions at a single time so
we have basically prepared this Python
script which actually contains multiple
threads
and at concurrently it executes multiple
functions so let me just show you as I
run this Python script you will
see it is basically executing multiple
functions at the same time using uh the
concept of threading so threading as you
know that you can see both threads have
been finished executing
uh some programming language supports
multi-threading somes don't but in
Python as you all know it contains it's
a multi-threaded language it supports
multi-threading and JavaScript is a
single-threaded language c++ also
supports multi-threading java also
supports multi-threading so similarly in
Python we actually use this module which
is
threading so this is actually I think
it's a third party module
so it makes it easy to implement so just
search for this module which is
threading yeah so I think yeah this is
actually the
module by
default you install this pip install
threading 2 but you import this so I
will show you the complete example the
link is given in the description
so it's a very simple example so first
of all you simply import the
module the time module which is a
built-in module and then from this
threading
module I think you don't need to install
this it's built in inside the latest
version of Python which is 3
uh the Python 3 it's built in the
multi-threading support so you simply
import this module from threading import
the thread class after that you simply
define we define two functions first
function which
actually expects a argument to be passed
here which is a countdown function and
now inside this while loop we
simply countdown to those number we
simply print
out so this function actually accepts an
integer to be passed to this function to
actually render out the countdown string
so very simple we have defined this
while loop we wait for 1 second and the
second function which will be
responsible again here we'll be
providing a simple print message actual
message plus the count variable and then
we loop through and display these are
two different functions and now I will
show you the concept of threading so how
we do this we
actually open a new thread by using this
thread class and we specify the target
what target code that you want to
execute so here I will display this
countdown function that we declared and
then we can provide the arguments right
here which is the
five like this similarly we'll be
defining the second thread again by
using the thread class and this time
we'll be executing the second function
that we defined which is print
messages and the arguments that we need
to pass here the first will be the
string value hello from thread two and
then
five so these are two different threads
calling two different functions so these
are the first thread this is a second
thread calling the second
function so after that now to start the
thread we call the start function so t1
start t2 start so both the threads are
starting one after the other and
uh optionally we can also call the join
function as well so that we get the
message whenever both the threads have
been finished so after that we can
simply print a line both threads have
finished so now what happen if I execute
this Python
script both the threads will start
concurrently and as you can
see multi-threading is implemented in
this format so we have taken a very
simple example you can see we executed
both the threads at the same time
concurrently and then we simply print
out that both threads have finished so
in this easy way guys you can get
started using multi-threading inside
Python using this threading
module you define whatever code that you
need to just assign them into different
functions and then define different
threads uh thank you very much for
watching this video and also check out
my website freemediattools.com
uh which contains thousands of tools