推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
x14oL
V2EX  ›  Python

Python 的监控程序

  •  
  •   x14oL · Apr 17, 2015 · 5858 views
    This topic created in 4179 days ago, the information mentioned may be changed or developed.
    需求:下发的任务会更新到数据库,python间隔时间段去查询数据库获取任务然后执行。

    主要功能都写好了,就是现在这个轮询的机制要怎么写比较好?

    现在能想到的就是sleep一段时间,然后执行一下。不过觉得这样写起来好简陋,也没考虑别的意外情况。

    是否有人有这样的经验?希望不吝赐教。
    11 replies  •  2015-04-21 10:52:07 +08:00
    rrfeng
        1
    rrfeng  
       Apr 17, 2015
    如果能保证每次循环都不出问题,再保证程序不会异常退出,那么就用 sleep 足以。

    要么就使用 cron 等系统服务来完成轮询,python 程序只负责每次的任务就好了。
    xia0chun
        2
    xia0chun  
       Apr 17, 2015
    linux下可以用cron定时去执行
    错误处理可以用try except else
    wy315700
        3
    wy315700  
       Apr 17, 2015
    sleep吧 然后错误输出到日志

    然后 sleep的时间 可以考虑TCP超时机制。

    每次增大,然后发现有任务以后,再降低
    Ghoul2005
        4
    Ghoul2005  
       Apr 17, 2015
    crontab定时触发
    任何的常驻进程都有意外退出的可能
    于是就出现了监控常驻进程的进城,以及用来监控“监控常驻进程的进程”的进程。。。
    所谓高可用就是自动容灾。
    julyclyde
        5
    julyclyde  
       Apr 17, 2015
    数据库不合适……万一两遍重叠执行了呢
    frankzeng
        6
    frankzeng  
       Apr 17, 2015
    用数据触发器调用外部的脚本,这方法应该可以
    loryyang
        7
    loryyang  
       Apr 17, 2015
    了解下supervisor?我们这边为了保障进程存活,会用这个
    xsseroot
        8
    xsseroot  
       Apr 17, 2015
    貌似有个APScheduler~
    fanta
        9
    fanta  
       Apr 17, 2015
    不如用生产消费模型.
    cheerzeng
        10
    cheerzeng  
       Apr 18, 2015 via Android
    @frankzeng 数据触发器有现成的模块吗?还是得自己写?
    bertram
        11
    bertram  
       Apr 21, 2015
    python celery任务调度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   824 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 21:27 · PVG 05:27 · LAX 14:27 · JFK 17:27
    ♥ Do have faith in what you're doing.