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 1016059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:29:37+00:00 2026-05-16T10:29:37+00:00

My django application takes forever to load so I’d like to find a way

  • 0

My django application takes forever to load so I’d like to find a way to measure the import latencies so I can find the offending module and make it load lazily.

Is there an obvious way to do this? I was considering tweaking the import statement itself to produce the latencies but I’m not sure exactly how to do that. I guess that it would be ideal to have the import tree (or DAG?) along with the latencies but just a list of latencies and import statements would be enough.

  • 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-05-16T10:29:38+00:00Added an answer on May 16, 2026 at 10:29 am

    You can redefine the __import__ built-in function to log the start and end times (delegating everything else to the original built-in __import__). That’s exactly the way to “tweak the import statement” in Python: redefine __import__!

    Edit: here’s a simple example…:

    import sys
    
    import __builtin__
    _orgimp = __builtin__.__import__
    
    import logging
    FORMAT = "%(asctime)-15s %(message)s"
    logging.basicConfig(format=FORMAT, level=logging.INFO)
    
    def __import__(name, *a):
      r = sys.modules.get(name)
      if r is not None: return r
      logging.info('import bgn %s', name)
      r = _orgimp(name, *a)
      logging.info('import end %s', name)
      return r
    __builtin__.__import__ = __import__
    
    import pyparsing
    

    This shows, on my system:

    2010-08-24 08:36:39,649 import bgn pyparsing
    2010-08-24 08:36:39,652 import bgn weakref
    2010-08-24 08:36:39,652 import bgn _weakref
    2010-08-24 08:36:39,653 import end _weakref
    2010-08-24 08:36:39,653 import end weakref
    2010-08-24 08:36:39,654 import bgn copy
    2010-08-24 08:36:39,655 import bgn org.python.core
    2010-08-24 08:36:39,656 import end copy
    2010-08-24 08:36:39,675 import end pyparsing
    

    Of course you can parse this log to show the nesting (what module first-imported what other modules) and “attempted imports” that failed (here, that of org.python.core from copy, no doubt in a try/except statement) as well as the time at which each import begins and concludes (the latter only if it does conclude, of course, not if it fails — easy to tweak with try/finally or whatever to get the exact behavior you prefer!-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Django manage.py runserver for developing my application (obviously), but it takes
I'm developing an application in python with django. User can upload a CSV file.
I am writing a web application with django on the server side. It takes
I'm writing a web application with Django where users can upload files with statistical
I've written a pretty simple Django application called django-locality which takes the headache out
I have a Django application which takes the lat/lon from a user's coordinates via
I have a django application, a blog. The entries for the blog can be
I would like to desing web application in django to make reservations for gym
My django application is having a handler for each functionality (e.g. Salesinvoice handler for
My django application has become painfully slow on the production. Probably it is due

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.