import threading
import requests
def test_thread():
"""线程运行函数"""
while True:
requests.get('https://网址')
def main():
for i in range(5):
# 创建线程
thread_hi = threading.Thread(target=test_thread)
# 启动线程
thread_hi.start()
print('start!')
main()
Thread 里面传参数要使用args进行传参
thread_hello = threading.Thread(target=test_thread, args=('hello', 1))
比如此。
对上述解释:
开启5个线程,每次for循环后,名字都是thread_hello,这样并不冲突。因为第二次for循环的时候,第一个thread_hello就失效了。