test.py 593 B

12345678910111213141516171819202122232425262728293031
  1. import time
  2. import requests
  3. import threading
  4. def http_get(url):
  5. response = requests.get(url)
  6. resp = response.text
  7. print(f"Response: {len(resp)}")
  8. def test():
  9. print('This is a test function in test.py')
  10. url = "https://yixue.cxhy.cn/api/test2"
  11. while True:
  12. for i in range(100):
  13. t = threading.Thread(target=http_get, args=(url,))
  14. t.setDaemon(True)
  15. t.start()
  16. print(f"Thread {i} started")
  17. # r = http_get(url)
  18. # print(len(r))
  19. time.sleep(3)
  20. if __name__ == '__main__':
  21. test()