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

关于 web 服务端超长时间任务,有条件的停止任务问题。

  •  
  •   itertools · May 23, 2018 · 1992 views
    This topic created in 3070 days ago, the information mentioned may be changed or developed.

    之前服务端遇到定时任务或者异步任务,都会用 celery 解决。

    但是这次需求是:用户在 a 时间点发送一个请求到 web 服务端,服务端就需要开始某个人物 taska,然后 ,可能在几个小时后,再发送一个请求到 web 服务端,(此次请求会包含一些任务停止的标准,比如:对 taska 处理结果希望到达某个值,或者某个时间点),之后,任务根据这次的参数判断什么时候停止。

    看了下 celery 貌似不符合这种场景,请教下,这种场景下有什么方案?谢谢! PS:停止的条件不是一开始就知道的(就是不能在任务开始的时候就知道任务结束条件的),需要任务开始一段时间,才能够得到,所以第二个请求一定要发的。

    1 replies  •  2018-05-24 18:21:47 +08:00
    sujin190
        1
    sujin190  
       May 24, 2018
    显然是需要在任务执行过程中不断检查结束任务条件是否达成,是则退出
    或者,任务启动之后再创建一个线程来执行实际任务,主线程则不断检查停止标记是否达成,是则停止任务线程执行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3439 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:48 · PVG 12:48 · LAX 21:48 · JFK 00:48
    ♥ Do have faith in what you're doing.