python - 如何定时从服务器下载一个文件?
大家讲道理
大家讲道理 2017-04-18 09:59:39
0
5
473
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(5)
左手右手慢动作

Method 1: sched module

# -*- coding:utf-8 -*-
import time
import os
import sched

# 初始化sched模块的scheduler类
# 第一个参数是一个可以返回时间戳的函数,第二个参数可以在定时未到达之前阻塞。
schedule = sched.scheduler(time.time, time.sleep)

# 被周期性调度触发的函数
def executeCommand(cmd, inc):
    os.system(cmd)
    # 循环执行
    schedule.enter(inc, 0, executeCommand, ('echo 又过了5秒钟', inc))


def main(cmd, inc=60):
    # enter四个参数分别为:间隔事件、优先级(用于同时间到达的两个事件同时执行时定序)、被调用触发的函数,
    # 给该触发函数的参数(tuple形式)
    schedule.enter(0, 0, executeCommand, (cmd, inc))
    schedule.run()


# 每5秒查发一次
if __name__ == '__main__':
    main('echo 过了5秒钟', 5)

Method 2: APScheduler framework

> [官方文档][1]
迷茫

You can use celery, asynchronous task framework, to set up scheduled tasks

巴扎黑

Set a scheduled task

伊谢尔伦

Is there any ready-made cron scheduled task scheduling under the Linux system (the main reason is that it is easy to learn, takes less time, and is very useful). Write a script to connect to the database, then insert data regularly, and then execute the script regularly. , by the way, there are a lot of crawlers!

洪涛

crontab

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template