簡單的python多線程併發

前些天學到的線程,做下記錄,以備後用:

程序如下:

import sys,time
import thread

def a():   
    for i in range(1,5):
        time.sleep(0.5)
        print "\nhello"
        time.sleep(1)

def b():
    for j in range(1,5):
        time.sleep(1)
        print "\nthen"       
        time.sleep(0.5)


thread.start_new_thread(a,())
thread.start_new_thread(b,())

 

線程1執行a(),線程2執行b(),爲了看出效果,加入time.sleep()

實驗驗證:
 

 

但是我移植到pyqt內時,發現報錯: Unhandled exception in thread started by <bound method MyForm.start2 of <__main__.MyForm object at 0x012C1348>>

google之,pyqt有自己的線程機制,好吧,繼續努力。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章