Car*_*l G 15 python multithreading
我在Python中知道的每个对象都可以通过调用来处理它的基类初始化:
super(BaseClass, self).__init__()
Run Code Online (Sandbox Code Playgroud)
这似乎与子类的情况不同threading.Thread,因为如果我尝试这个SubClass.__init__(),我得到:
RuntimeError: thread.__init__() not called
Run Code Online (Sandbox Code Playgroud)
什么给出了这个错误?我查看了源代码,threading.Thread看起来__init__应该设置该方法Thread.__initialized = True.我看到所有示例都使用以下内容__init__:
class YourThread(threading.Thread):
def __init__(self, *args):
threading.Thread.__init__(self)
# whatev else
Run Code Online (Sandbox Code Playgroud)
但为什么?
Ale*_*lli 42
这很好用:
>>> class MyThread(threading.Thread):
... def __init__(self):
... super(MyThread, self).__init__()
Run Code Online (Sandbox Code Playgroud)
我认为你的代码的错误是你将基类而不是当前的类传递给super- 即你正在调用super(threading.Thread, ...,而这是错误的.很难说,因为你没有显示你的失败代码,但这是我从你正在使用的语言中倾斜的推断! - )
| 归档时间: |
|
| 查看次数: |
15177 次 |
| 最近记录: |