filmov
tv
Python Network Programming 16 - Multithreading ( Socket Programming )

Показать описание
So for people who are unfamiliar with threading in Python, I am going to give you a quick overview of what threading is. When you want to do tasks parallel or simultaneously then you have to use the concept of threads.
Imagine there is a factory in which a lot people are working. These people are called workers. Each worker is doing a specific job. But all of the workers are working simultaneously to create a product. Similarly in our program you can think of threads as workers. We have 2 workers in our program who will have to work simultaneously. The first worker is going to handle connections and the second one is going to send commands.
----------------------------------
Now let's discuss how we are going to be coding threads into our program. We will create 3 functions in our program.
---
Now The second function is going to store jobs in QUEUE. If you remember at the starting we created a variable called job number and it is storing two elements in a list. We need to copy both of these elements to the queue. We are doing this because threads look for jobs in a queue and not in lists. The list format was only there so you could understand the concept of threads better.
---
The third function called the work function will distribute work according to the job number. If the job number in queue is 1 then it's going to make the thread handle connections and if it's 2 then send commands.
So these are the 3 functions that we will be creating in our code. Now that we are going to write the code things are going to get much clearer.
Next Video - Running the Multi-Client Program Live
#python
Комментарии