第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python線程參數(shù)問題

Python線程參數(shù)問題

瀟湘沐 2021-05-30 14:33:23
我已經(jīng)嘗試了大約半個小時,但似乎無法理解我在這里做錯了什么。工作代碼:import threadingfrom time import sleepdef printX():    threading.Timer(5.0, printX).start()    print("five")printX()while True:    print("1")    sleep(1)這有效,但是我需要能夠動態(tài)分配打印語句以及延遲。所需代碼:import threadingfrom time import sleepdef printX(time, message):    threading.Timer(int(time), printX).start()    print(str(message)printX(time, message)while True:    print("Rest of the program continues")    sleep(1)感謝您的任何幫助:)。
查看完整描述

2 回答

?
米脂

TA貢獻(xiàn)1836條經(jīng)驗 獲得超3個贊

另一種方法是使用printX 作為內(nèi)部函數(shù)定義一個類。


class thread:


    def __init__(self, time, message):

        self.time = time

        self.message = message


    def printX(self):

        threading.Timer(int(self.time), self.printX).start()

        print(str(self.message))


thread(3,"test message").printX()


while True:

    print("Rest of the program continues")

    sleep(1)


查看完整回答
反對 回復(fù) 2021-06-01
  • 2 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號