Now that we took care of how to establish the SSH connection, and interact with the network device, it's time to spice things up and add a new ingredient to our cake. And that's threading. Threading is used to run several function calls or other tasks concurrently, especially if those tasks involve some waiting times. This is the case for networking tasks, among others. For this purpose, I built the Create threads.py module, which contains code you've already seen earlier in the course, when we discussed the basics of threading. So in short, let me describe the functionality of this module.
The first thing to do, as always, is to import the necessary Python built in modules. In our case, we need a single module called threading. Next, we are creating the Create threads function right here, which takes two parameters, the list of IP addresses generally Based on the text file holding the addresses, and the function to execute, which is going to be the SSH function we discussed in the previous lecture. Inside the Create threats function, I have created an empty list called threads, and then iterating over the list of IP addresses provided as a parameter. So for IP enlist, we are creating and starting a thread for each address in the list using the thread class and the start method from within the threading module. For each iteration, we are appending the threads to the empty list we have created above using the append method.
And finally using another for loop to iterate over the threads list. We will use the join method in order to instruct the program to wait for all threads to finish. This way our application will be able to read from and configure multiple network devices simultaneously, which is an amazing feature to have in a network environment, saving you lots of time and effort. efforts and making your job easier. In the next lecture, we are going to put together everything we've built so far, and prepare for starting to test our application. So I'll see you in a moment.