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