• <bdo id='wlAlp'></bdo><ul id='wlAlp'></ul>

    <legend id='wlAlp'><style id='wlAlp'><dir id='wlAlp'><q id='wlAlp'></q></dir></style></legend>

    <small id='wlAlp'></small><noframes id='wlAlp'>

  • <i id='wlAlp'><tr id='wlAlp'><dt id='wlAlp'><q id='wlAlp'><span id='wlAlp'><b id='wlAlp'><form id='wlAlp'><ins id='wlAlp'></ins><ul id='wlAlp'></ul><sub id='wlAlp'></sub></form><legend id='wlAlp'></legend><bdo id='wlAlp'><pre id='wlAlp'><center id='wlAlp'></center></pre></bdo></b><th id='wlAlp'></th></span></q></dt></tr></i><div id='wlAlp'><tfoot id='wlAlp'></tfoot><dl id='wlAlp'><fieldset id='wlAlp'></fieldset></dl></div>

      <tfoot id='wlAlp'></tfoot>
      1. 在Django中调用.Delay()后,芹菜任务挂起

        时间:2024-08-21
          <i id='B7zev'><tr id='B7zev'><dt id='B7zev'><q id='B7zev'><span id='B7zev'><b id='B7zev'><form id='B7zev'><ins id='B7zev'></ins><ul id='B7zev'></ul><sub id='B7zev'></sub></form><legend id='B7zev'></legend><bdo id='B7zev'><pre id='B7zev'><center id='B7zev'></center></pre></bdo></b><th id='B7zev'></th></span></q></dt></tr></i><div id='B7zev'><tfoot id='B7zev'></tfoot><dl id='B7zev'><fieldset id='B7zev'></fieldset></dl></div>
            <legend id='B7zev'><style id='B7zev'><dir id='B7zev'><q id='B7zev'></q></dir></style></legend>
            • <bdo id='B7zev'></bdo><ul id='B7zev'></ul>
              1. <small id='B7zev'></small><noframes id='B7zev'>

                  <tfoot id='B7zev'></tfoot>

                    <tbody id='B7zev'></tbody>

                1. 本文介绍了在Django中调用.Delay()后,芹菜任务挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  从Django应用程序调用导入任务的.delay()方法时,进程停滞,请求从未完成。

                  我们在控制台上也没有收到任何错误。 使用PDB设置set_trace()会产生相同的结果。

                  检查了以下无助于解决问题的问题:

                  Calling celery task hangs for delay and apply_async

                  celery .delay hangs (recent, not an auth problem)

                  例如:

                  Backend/settings.py

                  CELERY_BROKER_URL = os.environ.get("CELERY_BROKER", RABBIT_URL)
                  CELERY_RESULT_BACKEND = os.environ.get("CELERY_BROKER", RABBIT_URL)
                  

                  后端/celery.py

                  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))
                  

                  app/tasks.py

                  import time
                  from celery import shared_task
                  
                  @shared_task
                  def upload_file(request_id):
                      time.sleep(request_id)
                      return True
                  

                  app/views.py

                  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.")
                  

                  推荐答案

                  问题与使用Django设置芹菜应用程序有关。我们需要确保在以下文件中导入并初始化芹菜应用程序:

                  backend\__init__.py

                  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',)
                  

                  这篇关于在Django中调用.Delay()后,芹菜任务挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:芹菜中如何向特定队列发送周期性任务 下一篇:如何在姜戈测试芹菜周期任务?

                  相关文章

                  <tfoot id='U5HhK'></tfoot>

                  1. <i id='U5HhK'><tr id='U5HhK'><dt id='U5HhK'><q id='U5HhK'><span id='U5HhK'><b id='U5HhK'><form id='U5HhK'><ins id='U5HhK'></ins><ul id='U5HhK'></ul><sub id='U5HhK'></sub></form><legend id='U5HhK'></legend><bdo id='U5HhK'><pre id='U5HhK'><center id='U5HhK'></center></pre></bdo></b><th id='U5HhK'></th></span></q></dt></tr></i><div id='U5HhK'><tfoot id='U5HhK'></tfoot><dl id='U5HhK'><fieldset id='U5HhK'></fieldset></dl></div>

                    <small id='U5HhK'></small><noframes id='U5HhK'>

                  2. <legend id='U5HhK'><style id='U5HhK'><dir id='U5HhK'><q id='U5HhK'></q></dir></style></legend>
                      • <bdo id='U5HhK'></bdo><ul id='U5HhK'></ul>