import threading
import requests
requests.packages.urllib3.disable_warnings()
urls_list = ["http://127.0.0.1:5000" for _ in range(1, 101)]
response_ok = 0
response_error = 0
def get_response_code(url):
global response_error
global response_ok
if requests.get(url).status_code == 200:
response_ok += 1
else:
response_error += 1
def get_response_code_thread(urls):
threads = []
for url in urls:
threads.append(
threading.Thread(target=get_response_code, args=(url,))
)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
if __name__ == '__main__':
get_response_code_thread(urls_list)
print(response_error)
print(response_ok)
标签:__,code,thread,get,python,接口,threads,多线程,response
From: https://www.cnblogs.com/chron/p/17342216.html