• <tfoot id='9Lvo1'></tfoot>

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

    <small id='9Lvo1'></small><noframes id='9Lvo1'>

      <bdo id='9Lvo1'></bdo><ul id='9Lvo1'></ul>

        如何跟踪形成芹菜和弦首部的组内单个任务的进度?

        How to track the progress of individual tasks inside a group which forms the header to a chord in celery?(如何跟踪形成芹菜和弦首部的组内单个任务的进度?)

        1. <legend id='3K77V'><style id='3K77V'><dir id='3K77V'><q id='3K77V'></q></dir></style></legend>

          <small id='3K77V'></small><noframes id='3K77V'>

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

                  本文介绍了如何跟踪形成芹菜和弦首部的组内单个任务的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  import celery
                  def temptask(n):
                      header=list(tempsubtask.si(i) for i in range(n))
                      callback=templink.si('printed at last?')
                      r = celery.chord(celery.group(header))(callback)
                      return r
                  
                  @task()
                  def tempsubtask(i):
                      print i    
                      for x in range(i):
                          time.sleep(2)
                          current_task.update_state(
                              state='PROGRESS', meta={'completed': x, 'total': i })
                  
                  @task()
                  def templink(x):
                      print 'this should be run at last %s'%x
                  
                  #executing temptask
                  r = temptask(100)
                  
                  我希望访问由tempsubtask更新的进度状态。我如何着手实现它?

                  推荐答案

                  搜索了几个小时后,我偶然发现了http://www.manasupo.com/2012/03/chord-progress-in-celery.html。虽然那里的解决方案对我来说不是开箱即用的,但它确实激励了我尝试类似的东西。

                  from celery.utils import uuid
                  from celery import chord
                  
                  class ProgressChord(chord):
                  
                      def __call__(self, body=None, **kwargs):
                          _chord = self.type
                          body = (body or self.kwargs['body']).clone()
                          kwargs = dict(self.kwargs, body=body, **kwargs)
                          if _chord.app.conf.CELERY_ALWAYS_EAGER:
                              return self.apply((), kwargs)
                          callback_id = body.options.setdefault('task_id', uuid())
                          r= _chord(**kwargs)
                          return _chord.AsyncResult(callback_id), r
                  

                  我使用的不是celery.chord,而是ProgressChord,如下所示:

                  def temptask(n):
                      header=list(tempsubtask.si(i) for i in range(n))
                      callback=templink.si('printed at last?')
                      r = celery.Progresschord(celery.group(header))(callback)
                      return r
                  

                  r的返回值包含同时具有回调异步结果和组结果的元组。所以成功看起来是这样的:

                  In [3]: r
                  Out[3]: 
                  (<AsyncResult: bf87507c-14cb-4ac4-8070-d32e4ff326a6>,
                   <GroupResult: af69e131-5a93-492d-b985-267484651d95 [4672cbbb-8ec3-4a9e-971a-275807124fae, a236e55f-b312-485c-a816-499d39d7de41, e825a072-b23c-43f2-b920-350413fd5c9e, e3f8378d-fd02-4a34-934b-39a5a735871d, c4f7093b-9f1a-4e5e-b90d-66f83b9c97c4, d5c7dc2c-4e10-4e71-ba2b-055a33e15f02, 07b1c6f7-fe95-4c1f-b0ba-6bc82bceaa4e, 00966cb8-41c2-4e95-b5e7-d8604c000927, e039c78e-6647-4c8d-b59b-e9baf73171a0, 6cfdef0a-25a2-4905-a40e-fea9c7940044]>)
                  

                  我继承并重写了[celery.chord][1]而不是[celery.task.chords.Chord][2],因为我在任何地方都找不到它的源。

                  这篇关于如何跟踪形成芹菜和弦首部的组内单个任务的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                        <bdo id='Ik1qq'></bdo><ul id='Ik1qq'></ul>
                        <legend id='Ik1qq'><style id='Ik1qq'><dir id='Ik1qq'><q id='Ik1qq'></q></dir></style></legend>

                        1. <small id='Ik1qq'></small><noframes id='Ik1qq'>

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

                            <tfoot id='Ik1qq'></tfoot>