OK so we go on to multi-threading For that let's agree and you package new pipe and package let's call
it as multi-threading.
So in this particular package let's go for a new python file.
Let's call it as you know multi-threading one.
OK.
Now in this particular multi-threading what we can do is we can say from trading import script straight
so threading is the model that is going to be used.
And trade is the class that we're going to use from the trading model in order to create the thread.
So I'll just right there from trading mondial.
We need to import the third class
for forgetting for creating multi-threading objects.
OK.
Ready.
Cool.
So now I have from serving in poultry what I need to do is I need to create an object lets say the object
is once.
OK.
So I create an object.
OK so I need to create a thread object so let me say I'll create a thread object by calling the thread
class so I can do it by just saying want equal the thread.
But over here I need to see target.
I need to define a keyword argument target as some function which needs to be called whenever the thread
is started.
When the thread is started so you get I'm just creating a thread object.
But I need to call this particular function when my thread is started so I can started by saying T-1
not start.
But if you want to start with only you know I need to call this.
We'll start by excluding those lines of code which are there and they're fun.
Fun is not the X currently so I need to define one function.
Ok Rich what really do let's say what this guy does is it grins.
Hi from Michelin.
Now what I'm going to do is I'm going to sleep in.
I'm going to sleep for 5 seconds.
This particular mattered and go to sleep or I'm going to cause a belly to happen so I'm going in for
time and from time I'm going to say time or sleep I need to say how many seconds I need to sleep.
Sometimes I sleep five seconds and after that I need to print saying after saying hi for my fun.
I need to say hi.
I woke up right or let's say hi.
Instead of seeing eye I'll see effort.
OK and no of it will come back right.
So T-1 that start will start that thread.
OK we'll start with the main program.
What will the main program do at that time.
So the main program has begun the thread and this thread will call the one function correct will call
the one function for the main program in meantime.
What this guy put in just.
Hi from Mean Mean also goes off to sleep for let's say 5 seconds and print.
Hi Main got up but after getting up or before getting whatever this guy's going to wait until the thread
that has begun joins back gets finished and then the main execution of the program stops.
So if I save it and if I the control chip death then high remain high for mean I from fun funding I
mean so.
Oh and then higher Mikalah then high I mean.
So I from so far as when this one does start if one was called high from if one was printed.
But when this guy was sleeping in the meantime the next line also got printed pretty high from men these
girls went off to sleep or things are happening simultaneously.
And then it printed high Effron got up high men got up into the child are able to understand these are
a few things that happen when you come to multi-tracking.
All right.
What if I were to create multiple threads and I want to pass arguments to the function like say for
example I want to create multiple threats something like this I'll show it to you.
So I'll say for I in range let me say 10.
I want to just create different threads.
I want to create different threads.
OK a thread I want to create a thread in each loop in each direction I want to create a thread and after
each iteration after creating a thread all I need to do is I need to set up to start right.
So in each of the times the target should be the target should be F1 but in F1 I should be able to print.
I should be able to print.
I should be able to print the value of i which is being passed from you.
So that means you take away your own variable let me call it as now or ratters all the keywords.
Let me call it.
Yeah.
Let me say.
Or your argument.
OK so all I did was I a pretty high from a fund with argument coming energy right.
OK so I need to print that
OK and high Effron woke up with argument
instead of saying there is a plus.
Convert it into a string SDR BRG
right.
So that becomes a one print state.
So why do a T-Dog start and Tiger fine.
Now I need to send the arguments so I'd need to set it that energy is equal to.
I need to send it in a top alternate and the top will I need to send the value by with a comma because
I have a set of that's two values not just one.
So I'm going to send those.
I'm going do this for multi-threading and then I'm going to run this.
Let me say control chip Destin.
Hi from from the documents you wrote without even one given to all of these different functions you
could add and then suddenly high if one woke up after after five seconds write higher on workable arguments
you 1 9 8 7 6 0.
But they are not knotter Why.
Because thread you can never predict when they wake up in what order will they wake up or what.
Get securites very difficult because the machine because of the system which is being executing this.
So it runs again.
All right.
All of them are just started and then all of them will stop by seeing higher woke up right.
So you can just have a look at what happens.
Different threads have started different threads stopped and then it says process finished with Mexico.
That's right.
So these are a few things that we need to understand about multi-threading.
Now we are going to use this concept of multi-threading to create a checkbox where chat but given the
client is going to top the server.
Ok the client is going to talk to the server the server is gonna talk to the client and both of them
need to happen simultaneously.
And of course we need multi-threading for same right so we got to do that in the next session.