python - Python:如何设置触发函数的时间?
问题描述
如何设置计时器来运行功能?现在我手动运行该功能。但是如果我想告诉 Python 在 1 小时内运行它呢?我怎样才能完成这项任务?此外,尝试在今天或明天下午 5 点运行它怎么样?
我尝试了以下但并没有真正起作用。我错过了什么?
import datetime
from threading import timer
def hello_world():
print("hello world")
delta_t = datetime.time(0,1,0)
Timer(delta_t, hello_world)
解决方案
import threading
def task():
print("hello world ")
timer = threading.Timer(5.0, task)
timer.start()
推荐阅读
- sql - 为什么此选择不选择任何行
- java - 如何使用java在mysql中插入枚举列类型
- zsh - Zsh 随时间更新提示
- azure - Azure SignalR 协商失败
- node.js - Axios 只为程序中的一个函数返回 HTML 而不是 JSON
- python - Python:分析股价在股票图表中被交叉的次数
- python - ValueError:权重不能广播到值。值.rank=3。权重.rank=1。values.shape=(?, 7, 7)。weights.shape=(?,)
- machine-learning - GenSims FastText 实施中的监督培训和测试
- javascript - 如何仅使用javascript获取没有id的标签文本
- jquery - DataTables 使用 columnDefs 添加额外的列不起作用