網(wǎng)站首頁 編程語言 正文
Timeloop是一個庫,可用于運行多周期任務(wù)。這是一個簡單的庫,使用decorator模式在線程中運行標記函數(shù)。
首先安裝timeloop庫:
pip install timeloop
示例代碼:
from datetime import datetime, timedelta
from timeloop import Timeloop
tl = Timeloop()
def task():
now = datetime.now()
ts = now.strftime("%Y-%m-%d %H:%M:%S")
print(ts + '333!')
def task2():
now = datetime.now()
ts = now.strftime("%Y-%m-%d %H:%M:%S")
print(ts + "555555!")
@tl.job(interval=timedelta(seconds=2))
def sample_job_every_2s():
task()
@tl.job(interval=timedelta(seconds=5))
def sample_job_every_5s():
task2()
總結(jié)
原文鏈接:https://blog.csdn.net/weixin_44799217/article/details/127353838
相關(guān)推薦
- 2022-04-21 C#使用Chart繪制曲線_C#教程
- 2022-06-20 關(guān)于Golang獲取當前項目絕對路徑的問題_Golang
- 2022-03-14 文件上傳錯誤the request doesn't contain a multipart/form
- 2021-11-25 vc控制臺程序關(guān)閉事件時的處理方式及注意點詳解_C 語言
- 2022-10-14 matlab非線性最小二乘擬合
- 2022-05-20 C語言實現(xiàn)教務(wù)管理系統(tǒng)_C 語言
- 2022-07-18 CSS基礎(chǔ)語法和盒模型
- 2022-04-18 python?selenium在打開的瀏覽器中動態(tài)調(diào)整User?Agent_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支