WEBVTT

00:00.360 --> 00:07.110
OK so we go on to multi-threading For that let's agree and you package new pipe and package let's call

00:07.110 --> 00:09.360
it as multi-threading.

00:12.370 --> 00:17.640
So in this particular package let's go for a new python file.

00:17.860 --> 00:24.100
Let's call it as you know multi-threading one.

00:24.660 --> 00:25.290
OK.

00:25.330 --> 00:38.190
Now in this particular multi-threading what we can do is we can say from trading import script straight

00:38.590 --> 00:41.490
so threading is the model that is going to be used.

00:41.530 --> 00:48.850
And trade is the class that we're going to use from the trading model in order to create the thread.

00:49.240 --> 00:55.980
So I'll just right there from trading mondial.

00:57.010 --> 01:02.350
We need to import the third class

01:05.500 --> 01:15.720
for forgetting for creating multi-threading objects.

01:16.740 --> 01:17.700
OK.

01:18.180 --> 01:18.990
Ready.

01:19.000 --> 01:19.520
Cool.

01:19.540 --> 01:29.290
So now I have from serving in poultry what I need to do is I need to create an object lets say the object

01:29.290 --> 01:32.330
is once.

01:32.550 --> 01:32.860
OK.

01:32.900 --> 01:34.490
So I create an object.

01:34.820 --> 01:42.080
OK so I need to create a thread object so let me say I'll create a thread object by calling the thread

01:42.080 --> 01:45.580
class so I can do it by just saying want equal the thread.

01:45.720 --> 01:49.640
But over here I need to see target.

01:49.640 --> 01:57.410
I need to define a keyword argument target as some function which needs to be called whenever the thread

01:58.130 --> 01:59.600
is started.

01:59.660 --> 02:03.060
When the thread is started so you get I'm just creating a thread object.

02:03.230 --> 02:11.270
But I need to call this particular function when my thread is started so I can started by saying T-1

02:11.300 --> 02:12.730
not start.

02:12.920 --> 02:18.550
But if you want to start with only you know I need to call this.

02:18.730 --> 02:23.560
We'll start by excluding those lines of code which are there and they're fun.

02:23.680 --> 02:29.040
Fun is not the X currently so I need to define one function.

02:29.560 --> 02:36.020
Ok Rich what really do let's say what this guy does is it grins.

02:36.920 --> 02:38.830
Hi from Michelin.

02:39.010 --> 02:44.850
Now what I'm going to do is I'm going to sleep in.

02:44.980 --> 02:47.830
I'm going to sleep for 5 seconds.

02:47.830 --> 02:53.380
This particular mattered and go to sleep or I'm going to cause a belly to happen so I'm going in for

02:53.380 --> 03:00.520
time and from time I'm going to say time or sleep I need to say how many seconds I need to sleep.

03:00.520 --> 03:08.610
Sometimes I sleep five seconds and after that I need to print saying after saying hi for my fun.

03:08.890 --> 03:12.280
I need to say hi.

03:12.310 --> 03:17.340
I woke up right or let's say hi.

03:17.340 --> 03:20.070
Instead of seeing eye I'll see effort.

03:20.740 --> 03:24.540
OK and no of it will come back right.

03:24.540 --> 03:27.060
So T-1 that start will start that thread.

03:27.390 --> 03:29.190
OK we'll start with the main program.

03:29.190 --> 03:31.780
What will the main program do at that time.

03:31.950 --> 03:38.130
So the main program has begun the thread and this thread will call the one function correct will call

03:38.130 --> 03:42.140
the one function for the main program in meantime.

03:42.200 --> 03:45.990
What this guy put in just.

03:46.410 --> 03:57.850
Hi from Mean Mean also goes off to sleep for let's say 5 seconds and print.

03:58.510 --> 04:09.710
Hi Main got up but after getting up or before getting whatever this guy's going to wait until the thread

04:09.710 --> 04:16.280
that has begun joins back gets finished and then the main execution of the program stops.

04:16.280 --> 04:23.330
So if I save it and if I the control chip death then high remain high for mean I from fun funding I

04:23.510 --> 04:24.340
mean so.

04:24.590 --> 04:27.420
Oh and then higher Mikalah then high I mean.

04:27.710 --> 04:36.160
So I from so far as when this one does start if one was called high from if one was printed.

04:36.170 --> 04:41.040
But when this guy was sleeping in the meantime the next line also got printed pretty high from men these

04:41.150 --> 04:44.240
girls went off to sleep or things are happening simultaneously.

04:44.360 --> 04:52.040
And then it printed high Effron got up high men got up into the child are able to understand these are

04:52.040 --> 04:55.760
a few things that happen when you come to multi-tracking.

04:55.760 --> 04:56.240
All right.

04:56.330 --> 05:01.850
What if I were to create multiple threads and I want to pass arguments to the function like say for

05:01.850 --> 05:06.160
example I want to create multiple threats something like this I'll show it to you.

05:06.380 --> 05:14.960
So I'll say for I in range let me say 10.

05:15.130 --> 05:19.340
I want to just create different threads.

05:19.550 --> 05:20.970
I want to create different threads.

05:20.990 --> 05:28.130
OK a thread I want to create a thread in each loop in each direction I want to create a thread and after

05:28.130 --> 05:36.720
each iteration after creating a thread all I need to do is I need to set up to start right.

05:36.860 --> 05:45.820
So in each of the times the target should be the target should be F1 but in F1 I should be able to print.

05:46.460 --> 05:48.580
I should be able to print.

05:48.830 --> 05:54.960
I should be able to print the value of i which is being passed from you.

05:54.980 --> 06:01.160
So that means you take away your own variable let me call it as now or ratters all the keywords.

06:01.220 --> 06:03.130
Let me call it.

06:04.880 --> 06:05.280
Yeah.

06:05.520 --> 06:06.880
Let me say.

06:07.170 --> 06:09.240
Or your argument.

06:09.490 --> 06:20.440
OK so all I did was I a pretty high from a fund with argument coming energy right.

06:20.580 --> 06:22.250
OK so I need to print that

06:25.610 --> 06:30.010
OK and high Effron woke up with argument

06:34.460 --> 06:37.810
instead of saying there is a plus.

06:37.820 --> 06:40.320
Convert it into a string SDR BRG

06:46.530 --> 06:47.080
right.

06:47.090 --> 06:48.870
So that becomes a one print state.

06:48.870 --> 06:54.610
So why do a T-Dog start and Tiger fine.

06:54.650 --> 07:00.270
Now I need to send the arguments so I'd need to set it that energy is equal to.

07:00.740 --> 07:07.100
I need to send it in a top alternate and the top will I need to send the value by with a comma because

07:07.100 --> 07:10.900
I have a set of that's two values not just one.

07:10.940 --> 07:13.180
So I'm going to send those.

07:13.530 --> 07:16.870
I'm going do this for multi-threading and then I'm going to run this.

07:16.880 --> 07:20.050
Let me say control chip Destin.

07:20.170 --> 07:25.400
Hi from from the documents you wrote without even one given to all of these different functions you

07:25.400 --> 07:31.040
could add and then suddenly high if one woke up after after five seconds write higher on workable arguments

07:31.040 --> 07:33.060
you 1 9 8 7 6 0.

07:33.080 --> 07:34.670
But they are not knotter Why.

07:34.700 --> 07:40.860
Because thread you can never predict when they wake up in what order will they wake up or what.

07:40.880 --> 07:47.170
Get securites very difficult because the machine because of the system which is being executing this.

07:47.270 --> 07:48.390
So it runs again.

07:48.410 --> 07:48.820
All right.

07:48.830 --> 07:56.200
All of them are just started and then all of them will stop by seeing higher woke up right.

07:56.330 --> 07:58.340
So you can just have a look at what happens.

07:58.340 --> 08:05.510
Different threads have started different threads stopped and then it says process finished with Mexico.

08:05.510 --> 08:07.090
That's right.

08:07.130 --> 08:11.630
So these are a few things that we need to understand about multi-threading.

08:11.720 --> 08:19.610
Now we are going to use this concept of multi-threading to create a checkbox where chat but given the

08:19.610 --> 08:21.670
client is going to top the server.

08:21.880 --> 08:25.670
Ok the client is going to talk to the server the server is gonna talk to the client and both of them

08:25.670 --> 08:27.660
need to happen simultaneously.

08:27.740 --> 08:33.110
And of course we need multi-threading for same right so we got to do that in the next session.
