<p>你的<code>__init__</code>方法是完全多余的。实际上,您正在用您自己的实现替换<code>Thread.__init__()</code>,您自己的实现只调用<code>Thread.__init__()</code>。如果你移除它,一切都不会改变:</p>
<pre><code>class Example(Thread):
def run (self):
print("It works!")
</code></pre>
<p>调用<code>Example.run()</code>方法很简单,因为您使用<a href="https://docs.python.org/2/library/threading.html#threading.Thread.start" rel="nofollow noreferrer">^{<cd5>} method</a>启动了线程:</p>
<blockquote>
<p><code>start()</code><br/>
Start the thread’s activity.</p>
<p>It must be called at most once per thread object. It arranges for the object’s <code>run()</code> method to be invoked in a separate thread of control.</p>
</blockquote>
<p>另请参见<a href="https://docs.python.org/2/library/threading.html#threading.Thread.run" rel="nofollow noreferrer">^{<cd6>} documentation</a>:</p>
<blockquote>
<p><code>run()</code><br/>
Method representing the thread’s activity.</p>
<p>You may override this method in a subclass. The standard <code>run()</code> method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.</p>
</blockquote>
<p>你的<code>__init__</code>方法与此无关。</p>
<p>现在,如果您在一个<code>Thread</code>子类中创建了一个<code>__init__</code>方法,然后没有确保调用了<code>Thread.__init__</code>,那么您就阻止了该类设置重要的实例信息,中断了实例:</p>
<pre><code>>>> from threading import Thread
>>> class Example(Thread):
... def run (self):
... print("It works!")
...
>>> Example().start()
It works!
>>> class BrokenExample(Thread):
... def __init__(self):
... # not doing anything
... pass
... def run (self):
... print("It works!")
...
>>> BrokenExample().start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../lib/python2.7/threading.py", line 737, in start
raise RuntimeError("thread.__init__() not called")
RuntimeError: thread.__init__() not called
</code></pre>
<p>因为这是一个常见的错误,所以<code>Thread.start</code>方法抛出一个自定义异常,显式地告诉您<code>Thread.__init__</code>没有执行。</p>