如何在 Jython 中从子线程杀死主线程

发布于 2024-08-11 22:59:18 字数 284 浏览 5 评论 0原文

我有一个脚本创建一个线程,60 秒后(该线程)需要终止主线程。我不确定可以使用什么命令来终止主线程。我正在使用 Jython 2.5.1 并且 Thread.interrupt_main 不起作用。

这是代码:

import threading
def exitFunct():
    #exit code here
t = threading.Timer(60.0, exitFunct)
t.start()
for i in range(1, 3000):
    print i

I have a script that creates a thread which after 60 seconds (this thread) needs to kill the main thread. I`m not sure what command I can use to kill the main thread. I'm using Jython 2.5.1 and Thread.interrupt_main doesn't work.

Here is the code:

import threading
def exitFunct():
    #exit code here
t = threading.Timer(60.0, exitFunct)
t.start()
for i in range(1, 3000):
    print i

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

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

发布评论

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

评论(1

不打扰别人 2024-08-18 22:59:18

如果线程总是在 60 秒后终止主线程,也许你最好使用 Thread.Join() 在你的主线程中超时?

以及关于 线程 的 jython 文档的链接,

尽管我想到了这一点这会阻塞你的主线程..

它看起来也像答案这里将为您提供帮助。

如果您发布一些示例代码来解释您的问题并更深入地解释您试图用它实现的目标,您会得到一些更好的回复:)

If the thread always terminates the main thread after 60 seconds, perhaps you'd be better using Thread.Join() in your main thread with a timeout?

And a link to the jython doc on threading

Although it has occurred to me that this would block your main thread..

It also looks like the answers here will help you.

If you post some example code that explains your problem and a deeper explanation of what you are trying to achieve with it, you'll get some better responses :)

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