Python 芹菜任务在Django中调用.delay()后挂起

Python 芹菜任务在Django中调用.delay()后挂起,python,django,celery,Python,Django,Celery,从django应用程序调用导入的任务的.delay方法时,进程会被卡住,请求永远不会完成 我们在控制台上也没有得到任何错误。 使用pdb设置set_跟踪的结果也是一样的 审查了以下问题,这些问题无助于解决问题: 例如: backend/settings.py 后端/芹菜.py app/tasks.py app/views.py 问题在于使用Django设置芹菜应用程序。我们需要确保芹菜应用程序已导入并在以下文件中初始化: 后端\\uu初始化\\uuu.py CELERY_BROKER_URL =

从django应用程序调用导入的任务的.delay方法时,进程会被卡住,请求永远不会完成

我们在控制台上也没有得到任何错误。 使用pdb设置set_跟踪的结果也是一样的

审查了以下问题,这些问题无助于解决问题:

例如:

backend/settings.py 后端/芹菜.py app/tasks.py app/views.py
问题在于使用Django设置芹菜应用程序。我们需要确保芹菜应用程序已导入并在以下文件中初始化:

后端\\uu初始化\\uuu.py
CELERY_BROKER_URL = os.environ.get("CELERY_BROKER", RABBIT_URL)
CELERY_RESULT_BACKEND = os.environ.get("CELERY_BROKER", RABBIT_URL)
from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

app = Celery('backend')

app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
import time
from celery import shared_task

@shared_task
def upload_file(request_id):
    time.sleep(request_id)
    return True
from rest_framework.views import APIView

from .tasks import upload_file

class UploadCreateAPIView(APIView):
    # other methods...

    def post(self, request, *args, **kwargs):
        id = request.data.get("id", None)
        # business logic ...
        print("Going to submit task.")
        import pdb; pdb.set_trace()
        upload_file.delay(id)                  # <- this hangs the runserver as well as the set_trace()
        print("Submitted task.")
from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ('celery_app',)