timer === 調整了範例,讓 timer `t` 可在任意位置取消 timer 的運作,指令 `t.cancel()` ```python= import threading # global t t = None def set_interval(func, sec): global t def func_wrapper(): set_interval(func, sec) func() t = threading.Timer(sec, func_wrapper) t.start() def call(): print('hello!') if __name__ == "__main__": set_interval(call, 3) ``` ## Ref. [[Python 常用] 實現 setInterval 定時器圈呼叫函式功能](https://andy6804tw.github.io/2021/01/21/time-interval/) ###### tags: `實作相關`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up