python用列表实现一个定时器(python 定时器,实现每天凌晨3点执行的方法)
类别:脚本大全 浏览量:507
时间:2022-01-26 01:51:51 python用列表实现一个定时器
python 定时器,实现每天凌晨3点执行的方法如下所示:
|
''' Created on 2018-4-20 例子:每天凌晨3点执行func方法 ''' import datetime import threading def func(): print ( "haha" ) #如果需要循环调用,就要添加以下方法 timer = threading.Timer( 86400 , func) timer.start() # 获取现在时间 now_time = datetime.datetime.now() # 获取明天时间 next_time = now_time + datetime.timedelta(days = + 1 ) next_year = next_time.date().year next_month = next_time.date().month next_day = next_time.date().day # 获取明天3点时间 next_time = datetime.datetime.strptime( str (next_year) + "-" + str (next_month) + "-" + str (next_day) + " 03:00:00" , "%Y-%m-%d %H:%M:%S" ) # # 获取昨天时间 # last_time = now_time + datetime.timedelta(days=-1) # 获取距离明天3点时间,单位为秒 timer_start_time = (next_time - now_time).total_seconds() print (timer_start_time) # 54186.75975 #定时器,参数为(多少时间后执行,单位为秒,执行的方法) timer = threading.Timer(timer_start_time, func) timer.start() |
以上这篇python 定时器,实现每天凌晨3点执行的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/u011311291/article/details/80016859
您可能感兴趣
- python比较两文件内容(Python判断两个文件是否相同与两个文本进行相同项筛选的方法)
- python转图片为字符图(Python实现图片转字符画的代码实例)
- python3字符串怎么操作(Python3字符串encode与decode的讲解)
- python中如何遍历键(Python中按值来获取指定的键)
- python解析csv文件存到数据库(python读取csv和txt数据转换成向量的实例)
- pythonmatplotlib怎么设置图像(完美解决Python matplotlib绘图时汉字显示不正常的问题)
- pythonnumpy求行列式的值(Python numpy中矩阵的基本用法汇总)
- 怎样在python中散点图(python使用Plotly绘图工具绘制散点图、线形图)
- python微信消息模拟请求(python实现微信机器人: 登录微信、消息接收、自动回复功能)
- python排序的三种方法(Python实现插入排序和选择排序的方法)
- python创建字典的代码(Python创建字典的八种方式)
- python微信窗口内容获取(python使用wxpy轻松实现微信防撤回的方法)
- python中tryexcept的用法(对python中的try、except、finally 执行顺序详解)
- scrapy框架爬取小说的正文内容(Scrapy框架爬取Boss直聘网Python职位信息的源码)
- python把文件上传服务器(Python 实现两个服务器之间文件的上传方法)
- python redis锁的使用(Python操作redis实例小结String、Hash、List、Set等)
- 今天要吃什么(今天要吃什么菜)
- 三杨之一 南杨 杨溥 安贞履节,酿醴调羹,宰相之气(三杨之一南杨杨溥)
- 今天会下雨吗(今天会下雨吗小说)
- 追连续剧,品古今联4 明代三杨,联妙诗佳(追连续剧品古今联4)
- 三杨 共辅四朝帝王,构建明帝国内阁行政圈(三杨共辅四朝帝王)
- 红色文化进国企(红色文化进国企)
热门推荐
- php环境搭建windows系统(Windows环境下安装PHP Pear的方法图文教程)
- 网站如何提高用户体验
- css弹性布局设置每行显示指定个数(CSS实现多行多列的布局的实例代码)
- js event对象
- linux后台运行程序的命令(在后台运行Linux命令的方法)
- mysql中的默认mysql数据库作用(MySQL安装后默认自带数据库的作用详解)
- docker指定基础镜像命令(Docker重命名镜像名称和TAG操作)
- python实时输出图像(Python给图像添加噪声具体操作)
- html5基本标签详解(HTML5 通过Vedio标签实现视频循环播放的示例代码)
- python中内存管理机制(Python中整数的缓存机制讲解)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9