停止其他线程

时间:2017-03-10 20:32:20

标签: python python-requests

这是我的代码:

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循环中创建的其他线程。

怎么做?!

0 个答案:

没有答案
相关问题