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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:53:30+00:00 2026-06-15T03:53:30+00:00

I am not yet at the level where I have tools (or know how

  • 0

I am not yet at the level where I have tools (or know how to develop or use them) for testing and profiling seemingly simple things like my questions so I turn to you.

I have a function that checks a condition and based on that condition picks the best mathematical tool to work with (different modules) but this function is applied on windows of an array and so is looped. Different imports may occur from window to window but this leads me to wonder if the imports are actually being looped and if this is a performance issue at all.

Here is an example from the matplotlib source

def pause(interval):
    """
    Pause for *interval* seconds.

    If there is an active figure it will be updated and displayed,
    and the GUI event loop will run during the pause.

    If there is no active figure, or if a non-interactive backend
    is in use, this executes time.sleep(interval).

    This can be used for crude animation. For more complex
    animation, see :mod:`matplotlib.animation`.

    This function is experimental; its behavior may be changed
    or extended in a future release.

    """
    backend = rcParams['backend']
    if backend in _interactive_bk:
        figManager = _pylab_helpers.Gcf.get_active()
        if figManager is not None:
            canvas = figManager.canvas
            canvas.draw()
            show(block=False)
            canvas.start_event_loop(interval)
            return

    # No on-screen figure is active, so sleep() is all we need.
    import time
    time.sleep(interval)

If I in a loop alternate opening and closing figures will time be imported every other iteration? Or just imported the first time the import is called on and subsequent imports ignored?

Thanks

  • 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-15T03:53:32+00:00Added an answer on June 15, 2026 at 3:53 am

    After an import completes successfully, the imported module is cached in sys.modules and subsequent import statements will find the module in sys.modules so the module will not be reimported. You can force a module reimport with the reload builtin function.

    From the documentation:

    The first place checked during import search is sys.modules. This mapping serves as a cache of all modules that have been previously imported, including the intermediate paths. So if foo.bar.baz was previously imported, sys.modules will contain entries for foo, foo.bar, and foo.bar.baz.

    PEP 8 (the Python style guide) recommends that imports should be at the top of the file, not within methods. Valid reasons to break this rule (giving a “late import”) are if a module import is expensive and used only rarely in your program (and not at all in a typical execution), or to resolve a circular import dependency (though in that case you should try to resolve the circularity by splitting module functionality better). For a module like time, that is built in to Python, there’s very little reason to use a late import.

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

Sidebar

Related Questions

Up to this point we have not yet needed a new masterpage for our
I have the following query that I want it to show Not Yet instead
I am trying to do the following and I have not yet succeeded. I
When working with R, I feel like a have decent repertoire of tools and
I'm creating a cms and have not yet settled on the matter of where
I have an application that has not yet been optimised for xlarge tablet screens,
Since Intellij does not yet support the Play-Scala-Template-Engine I was thinking about using plain
I'm not yet a fan of integrated development environments, but I'm trying to overcome
Unfortunately, Devel::Cover does not yet work with threads. It doesn't work with prefork either.
Question related to PHP memory-handling from someone not yet very experienced in PHP: If

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.