Hello, in this python programming video, we are going to look at initiating a new thread for multi threading is an amazing feature built into Python. It's not just unique to Python, many languages support it. And it's one of the fundamental of modern computers than multi threading, we wouldn't be able to, you know, essentially, you know, process data. At the same time, he allows us to, you know, handle thread. They're lightweight, and he just allows them, they they can communicate with each other, they can act as separate processes. So he's essentially, you know, allows us to have multiple applications open and you know, do things and then application.
Even though we only have nothing one application, we might want to do several different things and make it look like the app and at the same time, and with simple stuff. You might not notice the delay but as you get into more advanced applications, multi threaded application Programming really does become a crucial aspect of it. So in this video is going to initiate a simple thread. So the first thing you need to do is g, u, s for slash bin, slash on free import underscore fluid and module import module as well. We're going to define the function this time read and a delay parameter in here we'll have a count that will equals zero, we'll say well, I'm going to do is sleep for the you know the amount of time that we're passing into the time functions that are basically going to be the time delays.
Now plus equals one vs. code. So this will be the thread and the actual, essentially the timer. Wow. So what we're going to do in the input so all the way through this sort of style of string we've done before, so feel free to go back to anything that you don't want to forget. Good. And now, Logan do a good Troy block underscore thread dot start.
So this will start a new thread for very simple start new thread yet we'll call the function that we created. And inside here we need to specify the parameters for a thread on the thread. One time and support one to print and print era Right now in the wild one cola. So save that, run it and go away again. So let's run the Fred era unable to initiate flow. So let's take a look at what's going on because something has gone wrong.
Okay? Okay. I'm just gonna go over code from the top so we have time function for a delay of one count equals zero walk can't be less than five time dot sleep delay. Yes, can plus equal one print center centers. Red comma Tony. Deciding time time time at my bed time a method.
Let's try running that now. Okay there we go and it is now working. So, our thread is running this should be this way should be called whenever to initiate Fred. So, Fred to being on able to initiate my source code is try this keto influence of fried times, Doc. See Time, Time Time, open flow Lucky buck bracket, okay, frag New Start new thread that was mistakenly passing the name, then the actual club separately. Everyone.
Okay, so this is a syntax error on my part. So what we're doing here, we are running both of the threads. If you were to change the time delay to the same start time delay, there's a very high probability that they'll print on the same line thread one and two will because they'll be burning at the same time. So we have a delay, the amount of time they learned is right here. So this is what the old style of initiating a thread in the next tutorial what we'll actually do is create a thread manually with the start and end that the moment is just gone through an infinite loop to get to and it controls the book So, okay, so save that. And that's it for this video.
Thanks for watching. I look forward to seeing you in the next Python program tutorial.