Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么';t super(Thread,self)。\uuuu init\uuuu()用于threading.Thread子类?_Python_Multithreading - Fatal编程技术网

Python 为什么';t super(Thread,self)。\uuuu init\uuuu()用于threading.Thread子类?

Python 为什么';t super(Thread,self)。\uuuu init\uuuu()用于threading.Thread子类?,python,multithreading,Python,Multithreading,我所知道的Python中的每个对象都可以通过调用: super(BaseClass, self).__init__() 对于threading.Thread的子类,情况似乎并非如此,因为如果我在子类中尝试此操作,我会得到: RuntimeError: thread.__init__() not called 是什么导致了这个错误?我查看了线程的源代码。Thread,它看起来像\uuuu init\uuu方法应该设置线程。我看到所有示例都使用以下\uuuu init\uuu: class Yo

我所知道的Python中的每个对象都可以通过调用:

super(BaseClass, self).__init__()
对于
threading.Thread
的子类,情况似乎并非如此,因为如果我在
子类中尝试此操作,我会得到:

RuntimeError: thread.__init__() not called
是什么导致了这个错误?我查看了
线程的源代码。Thread
,它看起来像
\uuuu init\uuu
方法应该设置
线程。我看到所有示例都使用以下
\uuuu init\uuu

class YourThread(threading.Thread):
    def __init__(self, *args):
        threading.Thread.__init__(self)
        # whatev else
但是为什么呢?

这很好:

>>> class MyThread(threading.Thread):
...   def __init__(self):
...     super(MyThread, self).__init__()
我认为您的代码的缺陷在于您正在将基本类传递到
super
,而不是当前的类,也就是说,您正在调用
super(threading.Thread,
,这是错误的。很难说,因为您没有显示失败的代码,但这是我从您使用的语言间接推断出来的!)