Python 在django中使用简单异步队列的最佳方法?

Python 在django中使用简单异步队列的最佳方法?,python,django,asynchronous,queue,celery,Python,Django,Asynchronous,Queue,Celery,我需要django view函数来触发一个任务,该任务将在后台运行,而不是阻塞响应 def my_task(client_information, unique_id): # task #do something that takes a while def my_view(request): # django view client_information = request.GET.get('whatever') # get some information passed

我需要django view函数来触发一个任务,该任务将在后台运行,而不是阻塞响应

def my_task(client_information, unique_id): # task
    #do something that takes a while

def my_view(request): # django view

    client_information = request.GET.get('whatever') # get some information passed from the client
    unique_id = generate_unique_id() # generate a unique ID for this task
    start_task(client_information, unique_id) # the interesting part: start the task with client information and unique id, but non blocking
    return JsonResponse({'id': unique_id})
我读过芹菜,但我看到的代码看起来有些过分,因为我不需要在进程之间进行任何进一步的通信,我真的希望有一个尽可能轻量级的解决方案。

是一个简单的基于数据库的队列,只需要在后台运行一个worker(通过
manage.py process\u tasks调用它)。如果你永远不会利用芹菜的好处,我认为这是你正在寻找的轻量级解决方案


安装扩展后,您可以定义一个方法并向其添加
@background(schedule=20)
装饰器,这将使它们自动在后台运行。有关详细信息,请参阅。

谢谢!我接受了这个答案,因为我认为它为我的问题提供了一个有效的解决方案。现在,我正试图用这个来解决这个问题。如果我遇到问题或对结果不满意,我将使用此解决方案。