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

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

如何取消python中的setInterval?

如何取消python中的setInterval?

肥皂起泡泡 2021-11-30 16:19:12
我正在使用此代碼doSomething每 3 秒調(diào)用一次函數(shù)。但我想要那個時候numeroPeticiones== 3,停止這樣做。我找了很多例子,但沒有一個有效。就我而言,即使numeroPeticiones== 3滿足的條件,我的函數(shù)仍將永遠(yuǎn)執(zhí)行。我該如何解決?import threadingfrom threading import TimernumeroPeticiones=0def doSomething():    global numeroPeticiones    numeroPeticiones=numeroPeticiones+1    print ("hello, world",numeroPeticiones)    if numeroPeticiones == 3:        print("cancel")        t.cancel()def set_interval(func, sec):     def func_wrapper():        set_interval(func, sec)         func()      t = threading.Timer(sec, func_wrapper)    t.start()    return t
查看完整描述

1 回答

?
明月笑刀無情

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

您可以執(zhí)行以下操作,如果 num 等于 3,則不會啟動計時器


from threading import Timer

num = 0


def hello():

    global num

    num += 1

    print("hello, world")

    if (num < 3):

        Timer(3, hello).start()



Timer(3, hello).start() 


查看完整回答
反對 回復(fù) 2021-11-30
  • 1 回答
  • 0 關(guān)注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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