[英]Celery non blocking client
import proj.tasks
import time
import sys
import socket
import logging
import datetime
lat_to, ts = proj.tasks.timeme(time.time()) <---- blocking call
lat_from = time.time() - ts
print lat_to, lat_from
Celery task blocks so I cant take advantage of many workers. 芹菜任务块,所以我不能利用许多工人。 Is it possible to make that a non blocking call?
是否可以拨打非阻塞电话?
NOTE: Ive looked at tornado-celery as an option for non blocking celery client but I am not sure if i like that approach as i need to launch tornado celery web server. 注意:我已经将龙卷风芹菜视为非阻塞芹菜客户端的一种选择,但是我不确定我是否喜欢这种方法,因为我需要启动龙卷风芹菜网络服务器。
When calling a celery task the method executes synchronously. 调用芹菜任务时,该方法将同步执行。 THe power of a task queue is putting a task on the queue and letting the workers asynchronously do their work.
任务队列的功能是将任务放在队列中,并让工作人员异步完成工作。
You can do this using the task. 您可以使用任务执行此操作。
delay
method. delay
方法。
I'm not quiet sure what delay does internally but it returns very quickly, and the work of your method is not actually being done when you call it, your task is just being put on the work queue. 我并不确定要在内部执行什么延迟,但是延迟会很快返回,并且调用该方法时,该方法的工作实际上并未完成,只是将您的任务放在了工作队列中。
tornado-celery works fine on my side, but it by default waits for task's result before callback, 龙卷风芹菜在我这边工作正常,但默认情况下它会在回调之前等待任务的结果,
class GenAsyncHandler(web.RequestHandler):
@asynchronous
@gen.coroutine
def get(self):
response = yield gen.Task(tasks.sleep.apply_async, args=[3])
self.write(str(response.result))
self.finish()
if you want to have task callback options as below, you can try my fork 如果您想使用以下任务回调选项,可以尝试使用我的fork
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.