Laci 1.0Did you try condition objects? threading.ConditionExample from the library reference:# Consume one itemcv.acquire()while not an_item_is_available():cv.wait()get_an_available_item()cv.release()# Produce one itemcv.acquire()make_an_item_available()cv.notify()cv.release()You can block a thread with a condition object by calling its ''wait()''method. You cancall the ''notify()'' method from another thread and that will ''interrupt''the blocked thread.It is not the very same thing, but I suspect you can use it for the samepurposes.Cheers,Laci 1.0 好吧,自从我发布以来,我没有得到任何答案。与此同时,我一直在寻找它。 2.3线程模块中添加了一些新内容。那是'interrupt_main。但不幸的是,这与我的预期相反;它打断了主线程。 毕竟,我对Python有点失望。 (很难过)Well, I haven''t got any answer since I posted it. Meanwhile, I havebeen searching for it myself. Something new has been added in 2.3 inthread module. That''s interrupt_main. But, unfortunately, it is theopposite of what I expected; It interrupts the main thread.After all this, I am a bit disappointed about Python. (it''s sad) 你有没有尝试过条件对象? threading.Condition 来自图书馆参考的例子: #消耗一个项目 cv.acquire()而不是an_item_is_available(): cv.wait() get_an_available_item() cv.release() #制作一件物品 cv.acquire() make_an_item_available( ) cv.notify() cv.release() 你可以通过调用''wait()来阻止一个带有条件对象的线程。方法。你可以从另一个线程调用''notify()''方法,这将中断'被阻塞的线程。 这不是一回事,但我怀疑你可以用它来达到相同的目的。 干杯, Laci 1.0 Did you try condition objects? threading.Condition Example from the library reference: # Consume one item cv.acquire() while not an_item_is_available(): cv.wait() get_an_available_item() cv.release() # Produce one item cv.acquire() make_an_item_available() cv.notify() cv.release() You can block a thread with a condition object by calling its ''wait()'' method. You can call the ''notify()'' method from another thread and that will ''interrupt'' the blocked thread. It is not the very same thing, but I suspect you can use it for the same purposes. Cheers, Laci 1.0 谢谢,但它没有给出解决方案。问题是有多个条件变量可以使用而且我必须中断线程否 什么条件变量正在等待。Thanks, but it doesn''t give a solution. The problem is that there canbe multiple condition variables and I have to interrupt the thread nomatter what condition variable is waiting. 这篇关于python的线程没有“中断”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 06:23