python销毁线程,重新启动Python中的线程

在Python 3.4项目中,为飞行软件创建线程时遇到问题,需要在线程发生I/O错误或类似故障时能自我重启。尝试通过检查线程是否存活并重新启动,但发现线程只能启动一次。然后使用字典存储初始线程并复制以重启,但遇到了TypeError。解决方案是捕获异常并在异常或正常退出时重新启动线程,或者创建可重启的线程子类。
摘要由CSDN通过智能技术生成

I'm trying to make threaded flight software for a project in Python 3.4, in which I need threads to restart themselves in case an I/O error occurs during a sensor read or another fluke crash like that. Therefore I am working on making a watchdog to check if threads have died and restarting them.

At first I attempted to just check if the thread was no longer alive and restart it, which did this:

>>> if not a_thread.isAlive():

... a_thread.start()

Traceback (most recent call last):

File "", line 2, in

File "c:\Python34\lib\threading.py", line 847, in start

raise RuntimeError("threads can only be started once")

RuntimeError: threads can only be started once

This behaviour makes sense from the standpoint of threadingand Python itself, but makes my job harder. So I implemented a solution using

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值