threading.Thread
クラスを作成すると、threading.Thread.__init__(self)
またはsuper(ClassName, self).__init__()
を強制的に使用するのはなぜですか?例えばなぜクラスでスレッド.__ init __()が必要なのですか?
:
class Threader(threading.Thread):
def __init__(self, _fp, _q):
threading.Thread.__init__(self)
self.path = _fp
self.queue = _q
def run(self):
# Do stuff
または
class Threader(threading.Thread):
def __init__(self, _fp, _q):
super(Threader, self).__init__()
self.path = _fp
self.queue = _q
def run(self):
# Do stuff
どちらの方法が働く、とほぼ同じことを行います。しかし、どちらかの方法を取り除いても.__init__()
の場合は、スタックに入れます:from thread.start(): thread.__init__() not called
。
自分自身を定義してはならないdef __init__()
.__init__()
メソッドの「置き換え」ですか?
私はthis他のSOの投稿を読んだことがあり、それは私が思ったものと一致して、同じスタックエラーが発生します。
なぜ「スレッド」クラスを改良するのですか?なぜ、 'Thread'をインスタンス化してそれを呼び出し可能なデリゲートにするのはなぜですか? 'my_thread = threading.Thread(target = my_callable)' –
@jameslarge構文は、GUIの更新でやっていることのほうがきれいです。 –