在尝试First steps with Celery中的示例时,我发现与class a {
public:
enum {test = 0};
};
class b {
public:
enum {test = 1};
};
class c {
public:
enum {test = 2 < 3 ? a::test : b::test};
};
int main()
{
int v = c::test;
}
和get()
的调用顺序有关的意外行为。
下面的两个代码示例使用的是来自First steps with Celery的经过稍微修改的task.py,并且我的Celery worker进程在后台运行:
ready()
此代码执行一个任务,并尝试通过第二个from celery import Celery
app = Celery('tasks', backend='rpc://', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
对象查找结果,但它会爆炸:
AsyncResult
但是,通过交换import tasks, celery, time
r0 = tasks.add.delay(1,1)
time.sleep(.1)
print('r0 result', r0.get(1)) # '2', expected
print('r0 ready?', r0.ready()) # 'True', expected
r1 = celery.result.AsyncResult(r0.id)
print('r1 ready?', r1.ready()) # 'False', not expected!
print('r1 result', r1.get(1)) # raises celery.exceptions.TimeoutError
和get()
,代码按预期运行:
ready()
这是怎么回事?