【Python】多线程
生活随笔
收集整理的這篇文章主要介紹了
【Python】多线程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import threading
import timeclass myThread (threading.Thread): #繼承父類threading.Threaddef __init__(self, threadID, name):threading.Thread.__init__(self)self.name = namedef run(self): #把要執行的代碼寫到run函數里面 線程在創建后會直接運行run函數while 1:print("Starting " + self.name)time.sleep(1)# 創建新線程
thread1 = myThread(1, "this is thread1")
thread2 = myThread(2, "this is thread2")
thread3 = myThread(3, "this is thread3")# 開啟線程
thread1.start()
thread2.start()
thread3.start()
?
轉載于:https://www.cnblogs.com/tiandsp/p/8504194.html
總結
以上是生活随笔為你收集整理的【Python】多线程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC实现微秒(十万分之一秒)休眠
- 下一篇: websocket python爬虫_p