我将芹菜与python 3.5一起使用。我正在使用链来执行序列化任务,并且只想一次处理单个任务。
以下代码可以正常工作:
@shared_task(name='dummy1')
def dummy1(val):
logger.info('received: ' + val)
with RedisLock('testing.pid',60*60):
try:
logger.info("Lock acquired by " + val)
res = chain(dummy2.s(val), dummy3.s(val)).delay()
logger.info("Lock released")
except Exception as e:
logger.exception(str(e))
@shared_task(name='dummy2')
def dummy2(val):
logger.info('Dummy2 : ' + val)
time.sleep(3)
logger.info('Dummy2 complete')
return None
@shared_task(name='dummy3')
def dummy3(prev, val):
logger.info('Dummy3 : ' + val)
time.sleep(3)
logger.info('Dummy3 complete')
RedisLock是基于分布式缓存的锁,用于一次运行单个任务。
但是,当我这样做时:
with RedisLock('testing.pid',60*60):
try:
logger.info("Lock acquired by " + val)
res = chain(dummy2.s(val), dummy3.s(val)).delay()
res.get() # blocking the process here
logger.info("Lock released")
该链条无法正常工作,并且经常崩溃。