Reptile Related Basic Technology Paper — Multi-Thread Thread and Queu Queue Application

from queue import< span style="color: #000000;"> Queue

from threading import Thread
class mydownloader(Thread):
def __init__(self,queue):
Thread.
__init__(self)
self.queue
= queue
def run(self):
i
= 0
mydict
={}
#print("Current queue capacity{}".format(self .queue.qsize()))
while True:
if self.queue.qsize()==0:
print("Perfect ending!")
break
print("Current queue capacity{} ".format(self.queue. qsize()))
print("Processing the {}th wave".format(i))
mydict
= self.queue.get()
print("I love{}, he has a good age this year{}".format(mydict["name"],mydict["age"]))
print("Queue capacity after processing{}".format(self.queue .qsize()))
i
+=1
def main():
queue
= Queue()
queue.put({
"name": "Jing Cheng ", "age span>": 21})
queue.put({
"name": "Chen Peichang< span style="color: #800000;">", "age": 19})
queue.put({
"name": "Li Zhi ", "age span>": 31})
queue.put({
"name": "Xu Xiaodong< span style="color: #800000;">", "age": 40})
queue.put({
"name": "< span style="color: #800000;">", "age": 36})
for i in range(2):
cpc
= mydownloader(queue)
cpc.daemon
=True
cpc.start()
queue.join()

#if __name__=="__main__":
main()

Result:


Current queue capacity 5

Processing the 0th wave
I love Cheng Jin, he is 21 years old this year
Queue capacity after processing 4
Current queue capacity 4

Current queue capacity 4
Processing the first wave
I love Chen Peichang, he is 19 this year
Queue capacity after processing 3
Current queue capacity 3

Processing the 0th wave

I love Li Zhi for the second wave. He is 31 this year.

Queue capacity after processing 2 I love Xu Xiaodong, he is 40 years old this year

Current queue capacity 1
Queue capacity after processing 1

Current queue capacity 1

Processing the third wave
I love Austria, he is 36 years old this year
The queue capacity after processing the first wave is 0

Perfect ending!

from queue import Queue

from threading import Thread
class mydownloader(Thread):
def __init__(self,queue):
Thread.
__init__(self)
self.queue
= queue
def run(self):
i
= 0
mydict
={}
#print("Current queue capacity{}".format(self .queue.qsize()))
while True:
if self.queue.qsize()==0:
print("Perfect ending!")
break
print("Current queue capacity{} ".format(self.queue. qsize()))
print("Processing the {}th wave".format(i))
mydict
= self.queue.get()
print("I love{}, he has a good age this year{}".format(mydict["name"],mydict["age"]))
print("Queue capacity after processing{}".format(self.queue .qsize()))
i
+=1
def main():
queue
= Queue()
queue.put({
"name": "Jing Cheng ", "age span>": 21})
queue.put({
"name": "Chen Peichang< span style="color: #800000;">", "age": 19})
queue.put({
"name": "Li Zhi ", "age span>": 31})
queue.put({
"name": "Xu Xiaodong< span style="color: #800000;">", "age": 40})
queue.put({
"name": "< span style="color: #800000;">", "age": 36})
for i in range(2):
cpc
= mydownloader(queue)
cpc.daemon
=True
cpc.start()
queue.join()

#if __name__=="__main__":
main()

Result:


Current queue capacity 5

Processing the 0th wave
I love Cheng Jin, he is 21 years old this year
Queue capacity after processing 4
Current queue capacity 4

Current queue capacity 4
Processing the first wave
I love Chen Peichang, he is 19 this year
Queue capacity after processing 3
Current queue capacity 3

Processing the 0th wave

I love Li Zhi for the second wave. He is 31 this year.

Queue capacity after processing 2 I love Xu Xiaodong, he is 40 years old this year

Current queue capacity 1
Queue capacity after processing 1

Current queue capacity 1

Processing the third wave
I love Austria, he is 36 years old this year
The queue capacity after processing the first wave is 0

Perfect ending!

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2053 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.