import threading
import time
global_list = []
def get_html(global_list):
while True:
if(len(global_list)):
item = global_list.pop()
print(item)
else:
print("No item to show")
def get_url(global_list):
for i in range(100):
global_list.append(i)
thread1 = threading.Thread(target=get_url,args=(global_list,))
thread2 = threading.Thread(target=get_html,args=(global_list,))
#thread3 = threading.Thread(target=get_html,args=(global_list,))
thread1.start()
thread2.start()
#thread3.start()
import threading
from queue import Queue
global_list = []
def get_html(queue):
status = 0
while True:
url = queue.get()
if (status == 2):
break
if(url):
print("url is ",url)
else:
status +=1
def get_url(queue):
for i in range(1000):
queue.put(i)
print("i is ",i)
if __name__ == "__main__":
news_queue = Queue(maxsize=1000)
thread1 = threading.Thread(target=get_url,args=(news_queue,))
thread2 = threading.Thread(target=get_html,args=(news_queue,))
#thread3 = threading.Thread(target=get_html,args=(global_list,))
thread1.start()
thread2.start()
#thread3.start()
>>>
i is 0
...
i is 9
url is 1
i is 10
i is 11
...
i is 31
i is 32
url is 2
i is 33
i is 34
网友评论