Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:07:41+00:00 2026-06-12T01:07:41+00:00

Possible Duplicate: How can I find all subclasses of a given class in Python?

  • 0

Possible Duplicate:
How can I find all subclasses of a given class in Python?

In my Django project, I have some subclass of Celery’s Task and PeriodicTask:

class CustomTask(Task):
    # stuff

class CustomPeriodicTask(PeriodicTask):
    # stuff

I need all Task classes to add some custom logging configuration. So I thought I can us __subclasses__, but this does not work:

>>> Task.__subclasses__()
[<unbound PeriodicTask>, <class handle_register of <Celery default:0xa1cc3cc>>]

Is it somehow possible to get all my Task and PeriodicTask subclasses in a dynamic way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:07:42+00:00Added an answer on June 12, 2026 at 1:07 am

    Celery maintains a registry of all tasks. This is how the worker can lookup a task by name when it receives a task message:

    from celery import current_app
    all_task_names = current_app.tasks.keys()
    all_tasks = current_app.tasks.values()
    foo_task = current_app.tasks['tasks.foo']
    
    all_task_classes = [type(task) for task in current_app.tasks.itervalues()]
    

    The task registry is only populated as the modules containing tasks are imported.
    If you have not imported all modules you can do like the celery worker does, and
    import all configured task module sources:

    current_app.loader.import_default_modules()
    

    NOTE: import_default_modules doesn’t exist before Celery 2.5, back then you’d have to
    do:

    from celery.loaders import current_loader
    current_loader().init_worker()
    

    NOTE2: Are you sure you want to edit all task classes like this? Celery comes with a number
    of ways to configure task classes, e.g.:

    CELERY_ANNOTATIONS = {
         '*': {
             'loglevel': logging.DEBUG,
             'logger': logging.getLogger('foo'),
         },
    }
    

    will set the ‘loglevel’ and ‘logger’ attributes of all tasks.
    Alternatively you can use a common base class:

    class MyTask(Task):
        abstract = True   # means this base task won't be registered
        loglevel = logging.DEBUG
        logger = logging.getLogger('foo'),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to find all possible subsets of a given array? How can
Possible Duplicate: Given two arrays a and b .Find all pairs of elements (a1,b1)
Possible Duplicate: jQuery: find all the parents up to a specific parent I have
Possible Duplicate: Operator[][] overload I've looked on the internet but can't find a definitive
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can
Possible Duplicate: Can I scroll a ScrollView programmatically in Android? I have a chat
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: Where can I find a tutorial for IdocScript for Stellent/Oracle UCM? Hi
Possible Duplicate: How to find all substrings of a string in PHP Find all
Possible Duplicate: Enumerate NSArray using blocks to find and store all indexe's of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.