2017-01-31 6 views
-1

私はPyQt4とPython 2.7を使用しています。マルチスレッドがtogatherに動作しません

私は同時に起動する2つの機能を持っています。しかし、2番目の関数は、最初の終了までは起動しません。

何が問題になりますか?

def testvision(): 
    x=5 
    while x>0: 
     print 'vision' 
     time.sleep(1) 
     x=x-1 
    print 'finish vision' 

def testforword(): 
    x=5 
    while x>0: 
     print 'froword' 
     time.sleep(1) 
     x=x-1 
    print 'finish forword' 

def Forword_thread(self): 

    t1 = threading.Thread(target=testvision()) 
    t2 = threading.Thread(target=testforword()) 
    t1.start() 

    t2.start() 
    t1.join() 
    t2.join() 

私はこのように関数を呼び出す:

self.pushbuttonForword.clicked.connect(self.Forword_thread) 

enter image description here

+2

イメージではなくコードを投稿してください。実行できない場合は誰も問題を再現できません。 – asongtoruin

+1

コードの大部分はまだ画像に残っています。 1行のコードは誰にも役立ちません。あなたのコードのエラーはあなたが提供したテキストの行にありません。テキストとしてコピー&ペーストできる[MCVE]を入力してください。 –

答えて

0

あなたはこのようなあなたのスレッドの作成:

:と同等です

t1 = threading.Thread(target=testvision()) 

つまり、現在のスレッドで関数testvision()が実行された場合、新しいスレッドは空のターゲットメソッドで作成されます。これはThread()と同じです。開始されると、このスレッドは(空の)run()メソッドを呼び出し、すぐに終了します。

正しい方法はt2ため

t1 = threading.Thread(target=testvision) 

同じ用いることであろう。

関連する問題