Python RuntimeError: thread.__init__() not called解决方法

yipeiwu_com6年前Python基础

在写一个多线程类的时候调用报错
RuntimeError: thread.__init__() not called

复制代码 代码如下:

class NotifyTread(threading.Thread): 
    def __init__(self, params): 
        threading.Thread.__init__(self)  #here。。。。。。 
        self.params = params 
     
    def run(self): 
        print "start notify............" 
        time.sleep(10) 
        print notify_tran(self.params) 
        print "end notify.............." 

在init中要先初始化Thread,然后在给参数赋值,就能解决了。
也就是不能缺少
threading.Thread.__init__(self)
这是一个使用的注意地方。

相关文章

Python中循环引用(import)失败的解决方法

前言 最近在开发智能家居项目hestia-rpi项目中,由于代码结构层级划分不合理,导致了循环引用(import)module失败的问题,错误如下: Traceback (most r...

python 用for循环实现1~n求和的实例

用for循环实现1~n求和的方法 def main(): sum = 0 n = int(input('n=')) for x in range(n): sum...

Python三元运算实现方法

本文实例讲述了Python三元运算实现方法。分享给大家供大家参考。具体分析如下: Python中没有像C++和Java等语言中的三元运算符,但是可以用if else语句实现相同的功能:...

使用pyqt5 tablewidget 单元格设置正则表达式

使用pyqt5 tablewidget 单元格设置正则表达式

tablewidget pyqt5的tablewidget组件比较特殊,每个方格可以装载其他组件来搭配实现不同的效果,所以在qtdesigner上找不到可视化直接设置mask或者其他可...

python连接mongodb密码认证实例

如下所示: from pymongo import MongoClient #建立和数据库系统的连接,指定host及port参数 client = MongoClient('loca...