Python终止的线程无法重新启动 [英] Python Terminated Thread Cannot Restart

查看:482
本文介绍了Python终止的线程无法重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在发生某些动作时被执行的线程.给定程序的逻辑,可能无法在线程的另一个实例仍在运行时启动该线程.但是,当我第二次调用它时,出现"RuntimeError:线程已启动"错误.我使用Thread.is_alive()函数添加了一个检查,看它是否还活着,并且实际上已经死了.

I have a thread that gets executed when some action occurs. Given the logic of the program, the thread cannot possibly be started while another instance of it is still running. Yet when I call it a second time, I get a "RuntimeError: thread already started" error. I added a check to see if it is actually alive using the Thread.is_alive() function, and it is actually dead.

我在做什么错了?

我可以根据需要提供更多详细信息.

I can provide more details as are needed.

推荐答案

线程无法重新启动.您必须重新创建线程才能重新启动.

Threads cannot be restarted. You must re-create the Thread in order to start it again.

这篇关于Python终止的线程无法重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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