Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
Last active December 17, 2015 12:29
Show Gist options
  • Save carlohamalainen/5610513 to your computer and use it in GitHub Desktop.
Save carlohamalainen/5610513 to your computer and use it in GitHub Desktop.
nondeterministic behaviour of inspect().active() in celery
######### blah.py #########
from time import sleep
from celery import Celery
from celery.task import Task
import logging
import traceback
import time
import random
celery = Celery('blah', backend='redis://localhost', broker='redis://localhost')
class SleepTest(Task):
def run(self, x):
while True:
time.sleep(1)
logging.debug('sleeping... ' + str(x))
######### run.py #############
from blah import SleepTest
for x in range(10):
job = SleepTest.apply_async(args=[x], kwargs={}, queue='blah')
print job
######### running ###########
#
# celery -A blah worker --loglevel=debug --no-color -Q blah --concurrency 100
####### Code the gives nondeterministic results:
from celery import Celery
from celery.result import AsyncResult
celery = Celery('blah', backend='redis://localhost', broker='redis://localhost')
from celery.task.control import inspect
print inspect().active()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment