这是我的代码:
import threading
import requests
class MyThread(threading.Thread):
def __init__(self, id):
threading.Thread.__init__(self)
self.id = id
def run(self):
print('Thread {0} is running...'.format(self.id))
req = requests.post(url='http://test.com', data={'id': id})
if req.json()['success']:
# stop other threads
print('Thread {0} is finished!'.format(self.id))
for id in range(0, 480):
t = MyThread(id)
t.start()
在每个帖子中我发送了很多请求。如果条件为真,我想停止在for循环中创建的其他线程。
怎么做?!