python crontab : 有阻塞和没有阻塞

# 有阻塞
import os
import subprocess
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
import ProcessManager


def restart_process(process_name, log_name):
    ProcessManager(process_name, log_name).restart()

if __name__ == "__main__":
    sched = BlockingScheduler()
    process_name, log_name = "process_name", "log_name"
    sched.add_job(restart_tick, CronTrigger.from_crontab('0 8 * * *'), args=[process_name, log_name])
    sched.start()


# 没有阻塞
# -*- coding: utf-8 -*-
"""
import datetime
import time

from apscheduler.schedulers.background import BackgroundScheduler

def hello():
    print("print = ", datetime.datetime.now())


if __name__=="__main__":
    sched = BackgroundScheduler()
    sched.add_job(hello, trigger='interval', seconds=3)
    print("开启")
    sched.start()
    is_start = True
    print("开始")
    try:
        while 1:
            time.sleep(1)
            if datetime.datetime.now().second > 30:
                if not is_start:
                    continue
                sched.pause()
                is_start = False
                print("暂停.........")
            else:
                if is_start:
                    continue
                sched.wakeup()
                sched.state = 1
                is_start = True
                print("开启.........")
    except (KeyboardInterrupt, SystemExit):
        sched.shutdown()
        print('退出程序!')



你可能感兴趣的:(python,开发语言)