zoukankan      html  css  js  c++  java
  • python schedule processor

    run some tasks which could look like CRON within linux/UNIX in python.

    Here's a demo which run on ubuntu12.04

    sudo pip install apscheduler

    then 

    1) run a task at determained time 指定时间运行某个程序

    2) run a task every period 指定周期运行某个程序

    For 1)

    here is a            aps1.py

    #coding: utf-8                                                                                                                 
    #特定时间运行                                                                                                                  
    from apscheduler.scheduler import Scheduler                                                                                    
    sched = Scheduler()                                                                                                            
    sched.daemonic = False                                                                                                         
    def job_function(text):                                                                                                        
        print text                                                                                                                 
    from datetime import datetime                                                                                                  
    #job = sched.add_date_job(job_function, datetime(2013, 10, 11, 02, 36, 00), ['Hello World'])                                   
    job = sched.add_date_job(job_function, datetime(2014, 10, 11, 02, 36, 00), ['Hello World'])                                    
    sched.start()  

    For 2)

    here is a             aps2.py

    #coding: utf-8                                                                                                                 
    # 间隔时间运行的                                                                                                               
    from apscheduler.scheduler import Scheduler                                                                                    
    import time                                                                                                                    
    sched = Scheduler()                                                                                                            
    sched.daemonic = False                                                                                                         
    def job_function():                                                                                                            
        print "wan si ni"                                                                                                          
        print time.strftime('%Y%m%d%H%M %S')                                                                                       
    sched.add_interval_job(job_function,  seconds=3)                                                                               
    sched.start()

    For more information, you could visit :   http://pythonhosted.org//APScheduler/   http://blog.csdn.net/chosen0ne/article/details/7842421

  • 相关阅读:
    POJ
    HDU
    POJ
    HDU
    HDU
    HDU
    POJ
    ZOJ
    ZOJ
    Kattis
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3732134.html
Copyright © 2011-2022 走看看