title: Celery: polling running tasks for results
body: <p>proj/</p>
  
  <p>celery.py</p>
  
  <pre><code>from __future__ import absolute_import
  
  from kombu import Exchange, Queue
  from celery import Celery
  
  app = Celery('proj',
               broker='redis://myredis.com',
               backend='redis://myredis.com',
               include=['proj.tasks'])
  
  a_exchange = Exchange('a_ex', type='topic')
  
  # Optional configuration, see the application user guide.
  app.conf.update(
      CELERY_TASK_RESULT_EXPIRES=3600,
      CELERY_DISABLE_RATE_LIMITS=True,
      CELERY_ROUTES = {"app.tasks.timeme": "a"}
  )
  
  if __name__ == '__main__':
      app.start()
  </code></pre>
  
  <p>tasks.py</p>
  
  <pre><code>from __future__ import absolute_import
  
  from proj.celery import app
  import time
  
  @app.task
  def timeme(ts):
      print 'hi'
      lat = time.time() - float(ts)
      return (lat, time.time())
  </code></pre>
  
  <p>do_tasks.py</p>
  
  <pre><code>import proj.tasks
  import time
  import sys
  
  stime = time.time()
  running = []
  while time.time() &lt; stime + 15:
      res = proj.tasks.timeme.apply_async(args=[time.time()], link=proj.tasks.timeme.s())
      running.append(res)
  
      for res in running:      #&lt;------------ this gets extremely slow if running gets big!
            if res.ready()
                print res.get()
  </code></pre>
  
  <p>In the above code, looping <code>running</code> and see whether it's ready for result or not takes a very long time as <code>running</code> gets bigger and bigger.</p>
  
  <p>Is there something like <code>select.select</code> or <code>poll/epoll</code> on running celery tasks?   </p>
  
  <p>So i can do something like the following:  </p>
  
  <pre><code>While running:
      read, w, e = select.select([running], [], [])
      print read.get()
      running.remove(read)
      break
  </code></pre>