推荐学习书目
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
slogon
V2EX  ›  Python

python 的定时任务需求该怎么处理好呢?

  •  
  •   slogon · Apr 1, 2014 · 14366 views
    This topic created in 4452 days ago, the information mentioned may be changed or developed.
    刚接触python不久,想实现这样一个需求,用django搭建一个小站,然后后台有个定时任务不断的在跑,跑出的结果推送到前端页面。(类似于前端页面右下角会弹出一个层,显示后端定时任务跑完的最新结果)不知道有没有现成模块可以调用?希望大家能给点意见,万分感激!
    19 replies    1970-01-01 08:00:00 +08:00
    slogon
        1
    slogon  
    OP
       Apr 1, 2014
    django的站点已经搭建好了,现在就是后台定时任务这块不知道怎么实现好。。。
    wibile
        2
    wibile  
       Apr 1, 2014
    celery!
    webjin
        3
    webjin  
       Apr 1, 2014
    crontab -e
    slogon
        4
    slogon  
    OP
       Apr 1, 2014
    @webjin 单独跑某个脚本用crontab是用过,要推送到前端不好处理吧?
    ritksm
        5
    ritksm  
       Apr 1, 2014
    slogon
        6
    slogon  
    OP
       Apr 1, 2014
    @wibile 多谢了,我先去了解一下
    pythonfan
        7
    pythonfan  
       Apr 1, 2014
    @ritksm 多谢啦
    frye
        8
    frye  
       Apr 1, 2014
    tron
    est
        9
    est  
       Apr 1, 2014   ❤️ 1
    uwsgi 自带cron
    Livid
        10
    Livid  
    MOD
    PRO
       Apr 1, 2014   ❤️ 2
    很多时候不想用 crontab 是因为担心无法放进代码目录么?

    可以用一个 cron.pp 的 puppet 文件来控制 /etc/cron.d 里的内容。
    kaneg
        11
    kaneg  
       Apr 2, 2014
    @ritksm 这个不错
    yueyoum
        12
    yueyoum  
       Apr 2, 2014 via Android
    怎么显示最新内容的?定时刷 还是 实时的?

    定时刷 还是用 crontab 的好,把结果放入 redis ,然后django再取出来就行

    实时的就上 socket io
    konakona
        13
    konakona  
       Apr 2, 2014
    一般是配合crontab 使用,扔一片几年前写的python+crontab

    其实原理非常简单,在unix下运行python都是执行命令:
    $ python filename.py

    而crontab 就是计划任务,使用它,只需要用文中提到的设定去进行时间触发即可。


    文:
    http://blog.crazyphper.com/?p=2703
    http://blog.crazyphper.com/?p=2701
    yinian1992
        14
    yinian1992  
       Apr 2, 2014 via Android
    celery beat!
    Crossin
        15
    Crossin  
       Apr 2, 2014
    比较关心如何“推送”到前端?
    rayind
        16
    rayind  
       Apr 2, 2014
    如果是想让django定时执行某些动作
    可以使用crontab执行custom management command
    http://stackoverflow.com/questions/573618/django-set-up-a-scheduled-job
    moyerock
        17
    moyerock  
       Apr 2, 2014
    celery 看起来不错哟
    zeayes
        18
    zeayes  
       Apr 2, 2014
    @Crossin 前端定时来后端拿数据
    fy
        19
    fy  
       Apr 8, 2014
    我也想问这个,不过我的需求是按时间戳做定时任务。好像celery干这个比较麻烦??
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1651 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 16:39 · PVG 00:39 · LAX 09:39 · JFK 12:39
    ♥ Do have faith in what you're doing.