zoukankan      html  css  js  c++  java
  • 用apscheduler写python定时脚本

    apscheduler 官方文档:http://apscheduler.readthedocs.io/en/latest/

    写一个后台定时任务,一般2个选择,一个是apscheduler,一个celery,apscheduler比较直观简单。

    安装:pip install apscheduler

    简单例子:-------------------------------------------------------------------------------------------

    >>> from apscheduler.schedulers.blocking import BlockingScheduler
    >>> import datetime
    >>> def say_now():
    ... print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    ...
    >>> scheduler = BlockingScheduler()
    >>> scheduler.add_job(func=say_now, trigger='cron', second='*/5')  #可以指定各种定时执行规则,非常全,详情见官方文档 http://apscheduler.readthedocs.io/en/latest/
    <Job (id=c1d3e4e331fd4f63b0a551f64c985354 name=say_now)>
    >>> scheduler.start()
    2018-08-12 18:57:10
    2018-08-12 18:57:15
    2018-08-12 18:57:20
    2018-08-12 18:57:25
    2018-08-12 18:57:30
    2018-08-12 18:57:35

    -------------------------------------------------------------------------------------------









  • 相关阅读:
    服务返返回状态码详解
    LeetCode#28 Implement strStr()
    LeetCode#58 Length of Last Word
    LeetCode#66 Plus One
    spooling技术
    文件的打开与关闭
    DMA方式与通道方式
    中断向量、向量中断、向量地址
    中断响应优先级和中断处理优先级
    I/O接口
  • 原文地址:https://www.cnblogs.com/yuzhaoblog/p/9463976.html
Copyright © 2011-2022 走看看