- 新写自己的Threading类
class MyThread(threading.Thread):#我的Thread类 判断流程结束没 用于os shell命令是否执行判断 def __init__(self,func = ""):#输入待执行函数名 我执行的函数没有参数就没有加args输入了 threading.Thread.__init__(self) self.func = func self.result = 1#未完成为1 标志位 # 调用start自动执行的函数 def run(self): self.result = self.func() self.result = 0#完成返回0
然后执行
class MyThread(threading.Thread):#我的Thread类 判断流程结束没 用于os shell命令是否执行判断 def __init__(self,func = ""):#输入待执行函数名 我执行的函数没有参数就没有加args输入了 threading.Thread.__init__(self) self.func = func self.result = 1#未完成为1 标志位 # 调用start自动执行的函数 def run(self): self.result = self.func() self.result = 0#完成返回0
这样就可以判断os.sysytem里语句是否执行完成是否
本文介绍了一种自定义Threading类的方法,通过创建MyThread类继承自threading.Thread,实现了对线程执行状态的判断,特别适用于监控osshell命令的执行情况。文章详细展示了MyThread类的初始化和run方法,通过设置标志位来判断任务是否完成。
2868

被折叠的 条评论
为什么被折叠?



