Jython 中 Interrupt_main() 的替代方案?

发布于 2024-08-13 07:37:02 字数 284 浏览 2 评论 0原文

每当在 Jython 中使用代码 thread.interrupt_main() 时,它实际上不会中断主线程。关于替代方案有什么想法吗?代码如下:

import threading
import dummy_thread as _thread
def exitFunct():
    _thread.interrupt_main()
t = threading.Timer(60.0, exitFunct)
t.start()
for i in range(1, 3000):
    print i

Whenever the code thread.interrupt_main() is used in Jython it doesn't actually interrupt the main thread. Any ideas as to alternatives? Code is below:

import threading
import dummy_thread as _thread
def exitFunct():
    _thread.interrupt_main()
t = threading.Timer(60.0, exitFunct)
t.start()
for i in range(1, 3000):
    print i

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-08-20 07:37:02

在您的计算机上列出 3000 个号码是否需要花费超过 60 秒的时间?看起来 main 在计时器触发之前就已经完成了,所以没有什么可以中断的,因为 main 已经退出了。不?

您也可以尝试使用 PyErr_SetInterrupt() 代替。

Does listing 3000 numbers take longer than 60 seconds on your machine? Looks like main is finished before the timer will fire so nothing to interrupt anymore as main already has exited. No?

You could also try using PyErr_SetInterrupt() instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文