新聞中心
過程說明

在嶗山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營(yíng)銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,嶗山網(wǎng)站建設(shè)費(fèi)用合理。
1、從Thread類構(gòu)成子類。覆蓋方法根據(jù)需要提供參數(shù)。
2、重寫線程的業(yè)務(wù)邏輯。
3、新的Thread子類一旦被定義,就必須對(duì)其進(jìn)行實(shí)例化,以啟動(dòng)新的線程。
然后,調(diào)用方法啟動(dòng)它。最后,它將調(diào)用方法來執(zhí)行業(yè)務(wù)邏輯。
實(shí)例
#python 多線程示例打印當(dāng)前日期。
#1. 使用 threading.Thread 類定義子類。
#2. 實(shí)例化子類并觸發(fā)線程。
import threading
import datetime
class myThread (threading.Thread):
def __init__(self, name, counter):
threading.Thread.__init__(self)
self.threadID = counter
self.name = name
self.counter = counter
def run(self):
print("\nStarting " + self.name)
print_date(self.name, self.counter)
print("Exiting " + self.name)
def print_date(threadName, counter):
datefields = []
today = datetime.date.today()
datefields.append(today)
print("{}[{}]: {}".format( threadName, counter, datefields[0] ))
# 創(chuàng)建新線程
thread1 = myThread("Thread", 1)
thread2 = myThread("Thread", 2)
# 啟動(dòng)新線程
thread1.start()
thread2.start()
thread1.join()
thread2.join()
print("\nExiting the Program!!!")以上就是python threading實(shí)現(xiàn)線程的過程,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
本文題目:創(chuàng)新互聯(lián)Python教程:pythonthreading實(shí)現(xiàn)線程的過程
網(wǎng)站鏈接:http://www.5511xx.com/article/cohoooo.html


咨詢
建站咨詢
