Python “如何杀死所有的小绿豆或结束”;而不是Queue.empty();环

Python “如何杀死所有的小绿豆或结束”;而不是Queue.empty();环,python,python-2.7,while-loop,queue,gevent,Python,Python 2.7,While Loop,Queue,Gevent,在这种情况下,如何在不使用sys.exit()的情况下结束Gevent? 我不需要完成列表中的所有元素,我只需要使用队列,直到找到一个字符串 tasks = Queue() while not tasks.empty(): string = tasks.get() con = validate(string) if con == True: break Break语句不起作用。 我开始这样的

在这种情况下,如何在不使用sys.exit()的情况下结束Gevent? 我不需要完成列表中的所有元素,我只需要使用队列,直到找到一个字符串

tasks = Queue()
while not tasks.empty():
            string = tasks.get()
            con = validate(string)
            if con == True:
                break
Break语句不起作用。 我开始这样的小绿球:

gevent.spawn(worker) 

我不能使用sys.exit(),因为我想迭代一个列表并为每个对象启动一个新的Gevent实例。

我不熟悉python,但尝试使用布尔值作为while循环的额外条件:

tasks = Queue()
found = False
while not found and not tasks.empty():
    string = tasks.get()
    found = validate(string)

我不熟悉python,但请尝试使用布尔值作为while循环的额外条件:

tasks = Queue()
found = False
while not found and not tasks.empty():
    string = tasks.get()
    found = validate(string)

非常感谢。这确实是打破循环的解决方案。我仍然在寻找一个解决方案,如何阻止其他的绿球。谢谢!这确实是打破循环的解决方案。不过,我仍在寻找一个解决方案,如何阻止其他的小绿球。