Python thread
生活随笔
收集整理的這篇文章主要介紹了
Python thread
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一種thread:定義threading的target,目標運行函數
import threadingdef worker():"""thread worker function"""print 'Worker'returnthreads = [] for i in range(5):t = threading.Thread(target=worker)threads.append(t)t.start() Worker Worker Worker Worker Worker第二種thread 定義自己的run函數
import threading import logginglogging.basicConfig(level=logging.DEBUG,format='(%(threadName)-10s) %(message)s',)class MyThread(threading.Thread):def run(self):logging.debug('running')returnfor i in range(5):t = MyThread()t.start() (Thread-1 ) running (Thread-2 ) running (Thread-3 ) running (Thread-4 ) running (Thread-5 ) running轉載于:https://www.cnblogs.com/shhu1993/p/4865951.html
總結
以上是生活随笔為你收集整理的Python thread的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么开展泰山地区的生态环境教育和宣传?
- 下一篇: 怎么开展泰山地区的生物多样性保护工作?