Python 为什么';t super(Thread,self)。\uuuu init\uuuu()用于threading.Thread子类?
我所知道的Python中的每个对象都可以通过调用: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
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,
,这是错误的。很难说,因为您没有显示失败的代码,但这是我从您使用的语言间接推断出来的!)