Celery Python revoke

2019-07-23 06:57发布

问题:

software -> celery:3.1.20 (Cipater) kombu:3.0.35 py:2.7.6
            billiard:3.3.0.22 py-amqp:1.4.9
platform -> system:Linux arch:64bit, ELF imp:CPython
loader   -> celery.loaders.default.Loader
settings -> transport:amqp results:amqp

Currently I have the following function:

task(bind=True, default_retry_delay=300, max_retries=3)
def A(self,a,b,c,**kwargs)
    .
    B()
    .
    .
    .
    code

This is the function I call to cancel A.

task(bind=True, default_retry_delay=300, max_retries=3)
def cancelA(self,a,b,c,**kwargs)
    revoke(job.reference, terminate=True)

When I call cancelA(), but function A() is in progress and executing function B(), task doesn't get REVOKED. I debug celery and I see that even after calling revoke the Task status in A() is PROGRESS, not REVOKED. Is this expected behavior? I noticed that when B() is not executing, just code inside A, Task is revoked properly. As workaround I sleep for few seconds after calling REVOKE to guarantee B() finished already.