python的线程没有“中断”? [英] python's threading has no "interrupt"?

查看:117
本文介绍了python的线程没有“中断”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,python'的线程模块模型在Java之后。

然而,我找不到相当于Java的中断的东西和

isInterrupted方法,以及InterruptedException。

" somethread.interrupt()"当它在

睡眠/等待状态时会唤醒一些线程。


有没有办法用python'的线程做到这一点?我想线程

中断是一个非常原始的功能,用于阻止被阻止的

线程。



As far as I know python''s threading module models after Java''s.
However, I can''t find something equivalent to Java''s interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it''s in
sleeping/waiting state.

Is there any way of doing this with python''s thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.

Jane

推荐答案

ja ********* **@hotmail.com (简奥斯汀)在留言中写道:< ba ************************** @ posted 。谷歌。 com> ...
ja***********@hotmail.com (Jane Austine) wrote in message news:<ba**************************@posting.google. com>...
据我所知,python'的线程模块模型在Java之后。
然而,我找不到与Java相同的东西。中断和
isInterrupted方法,以及InterruptedException。
somethread.interrupt()当它处于睡眠/等待状态时会唤醒一些线程。

有没有办法用python'的线程做到这一点?我认为线程
中断是一个非常原始的功能,用于阻止阻塞的线程。

Jane
As far as I know python''s threading module models after Java''s.
However, I can''t find something equivalent to Java''s interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it''s in
sleeping/waiting state.

Is there any way of doing this with python''s thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.

Jane




嗯,自从我发布以来,我没有得到任何答案。与此同时,我自己一直在寻找它。在

线程模块中的2.3中添加了一些新东西。那是'interrupt_main。但是,不幸的是,这与我的预期相反。

;它打断了主线程。


毕竟,我对Python有点失望。 (很难过)


Jane



Well, I haven''t got any answer since I posted it. Meanwhile, I have
been searching for it myself. Something new has been added in 2.3 in
thread module. That''s interrupt_main. But, unfortunately, it is the
opposite of what I expected; It interrupts the main thread.

After all this, I am a bit disappointed about Python. (it''s sad)

Jane


>
据我所知,python'在Java之后的线程模块模型。
然而,我找不到相当于Java'的中断和
isInterrupted方法的东西, InterruptedException。
" somethread.interrupt()"当它处于睡眠/等待状态时会唤醒一些线程。

有没有办法用python'的线程做到这一点?我认为线程
中断是一个非常原始的功能,用于阻止阻塞的线程。
As far as I know python''s threading module models after Java''s.
However, I can''t find something equivalent to Java''s interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it''s in
sleeping/waiting state.

Is there any way of doing this with python''s thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.


好吧,自从我发布以来,我没有得到任何答案。与此同时,我一直在寻找它。 2.3线程模块中添加了一些新内容。那是'interrupt_main。但不幸的是,这与我的预期相反;它打断了主线程。

毕竟,我对Python有点失望。 (很难过)


Well, I haven''t got any answer since I posted it. Meanwhile, I have
been searching for it myself. Something new has been added in 2.3 in
thread module. That''s interrupt_main. But, unfortunately, it is the
opposite 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



> >
据我所知,python'的线程模块模型在Java之后。
但是,我找不到相当于Java的中断和/或isInterrupted方法的东西,以及InterruptedException。
somethread.interrupt()当它处于睡眠/等待状态时会唤醒一些线程。

有没有办法用python'的线程做到这一点?我认为线程
中断是一个非常原始的功能,用于阻止阻塞的线程。
As far as I know python''s threading module models after Java''s.
However, I can''t find something equivalent to Java''s interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it''s in
sleeping/waiting state.

Is there any way of doing this with python''s thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.


好吧,自从我发布以来,我没有得到任何答案。与此同时,我一直在寻找它。 2.3线程模块中添加了一些新内容。那是'interrupt_main。但不幸的是,这与我的预期相反;它打断了主线程。

毕竟,我对Python有点失望。 (很难过)


Well, I haven''t got any answer since I posted it. Meanwhile, I have
been searching for it myself. Something new has been added in 2.3 in
thread module. That''s interrupt_main. But, unfortunately, it is the
opposite 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 can
be multiple condition variables and I have to interrupt the thread no
matter what condition variable is waiting.


这篇关于python的线程没有“中断”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆