美文网首页Django
2018-03-21 celery 子线程卡住导致任务不能结束解

2018-03-21 celery 子线程卡住导致任务不能结束解

作者: 多吃水果少吃肉 | 来源:发表于2018-03-21 18:03 被阅读2次

    http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_time_limit

    from celery.exceptions import SoftTimeLimitExceeded
    
    @app.task
    def mytask():
        try:
            return do_work()
        except SoftTimeLimitExceeded:
            cleanup_in_a_hurry()
    

    但是 TimeLimitExceeded 会直接杀掉进程,raise 一个 TimeLimitExceeded,不能被 task 捕捉,所以应该两种方案配合使用,soft_time_limit=小int,time_limit=大int,使用soft 试图关闭进程超时就会被干掉。

    相关文章

      网友评论

        本文标题:2018-03-21 celery 子线程卡住导致任务不能结束解

        本文链接:https://www.haomeiwen.com/subject/bkfnqftx.html