简体   繁体   English

芹菜非阻塞客户端

[英]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

  1. After task sent 任务发送后
  2. After task sent and ack-ed 任务发送并确认后
  3. To fit original celery behavior that task.apply_async() to get the AsyncResult first, then AsyncResult.get() to get actual task result in tornado asynchronous fashion 为了适应原始的芹菜行为,请使用task.apply_async()首先获取AsyncResult,然后使用AsyncResult.get()以龙卷风异步方式获取实际任务结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM