0

is_alive()を使用して、Python3.2であるスレッドを別のスレッドからテストしようとしています。で使用するthread1().is_alive()と、が実行されているかどうか の代わりにthread2取得します。falsetruethread1

中に入れても同じ結果になりますが、thread1().is_alive()中にthread1入れる と期待通りに戻ります。self.is_alive()thread1true

コマンドが必要であるかのように私には見えましたthread1.is_alive()が、それは1つの引数が必要であり、失敗することを示しています。

単純なものが欠けているように感じますが、それが何であるかを見つけることができませんでした。

ポインタをいただければ幸いです、ありがとう

わかりました。テストコードは次のようになります。

import threading
import time
#
class FirstThread(threading.Thread):
    def run (self):
        while 1:
            print ('This is the First thread')
            print(self.is_alive())
            time.sleep(1)
FirstThread().start()
#
class TestThread (threading.Thread):
    def run ( self ):
        while 1:
            print ('This is the thread alive test thread')
            print(FirstThread().is_alive()) 
            time.sleep(1)
TestThread().start()
4

1 に答える 1

2

初心者の間違い、開始された「最初の」スレッドオブジェクトは参照されず、FirstThread().is_alive()開始されない一時的なオブジェクトをテストします。

于 2015-02-19T10:04:02.097 に答える