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

  • Home
  • SEARCH
  • 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 7159359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:13:06+00:00 2026-05-28T13:13:06+00:00

I am looking for a way to correctly manage module level global variables that

  • 0

I am looking for a way to correctly manage module level global variables that use some operating system resource (like a file or a thread).

The problem is that when the module is reloaded, my resource must be properly disposed (e.g. the file closed or the thread terminated) before creating the new one.

So I need a better pattern to manage those singleton objects.

  • 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-28T13:13:07+00:00Added an answer on May 28, 2026 at 1:13 pm

    I’ve been reading the docs on module reload and this is quite interesting:

    When a module is reloaded, its dictionary (containing the module’s
    global variables) is retained. Redefinitions of names will override
    the old definitions, so this is generally not a problem. If the new
    version of a module does not define a name that was defined by the old
    version, the old definition remains. This feature can be used to the
    module’s advantage if it maintains a global table or cache of objects
    — with a try statement it can test for the table’s presence and skip
    its initialization if desired:

    try:
        cache
    except NameError:
        cache = {}
    

    So I could just check if the objects already exist, and dispose them before creating the new ones.

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

Sidebar

Related Questions

I've been trawling various sites looking for the correct way to manage switching. I
I'm writing some simple web apps in PHP/HTML/CSS/JS, and am looking for a way
I am looking here for some hints and tips on how to manage multiple
Is there a way to manage URL encoding with ActiveResource? Specifically I am looking
I am looking for a good way to manage the access to an external
I'm looking for a NoSQL-way to store machinedata like information about tools, work pieces,
Looking for the correct way and control to import and export of out of
I'm looking for (arguably) the correct way to return data from a XmlHttpRequest .
I am looking to the fastest and the correct way to check if a
I am looking at singletons and I was curious about the correct way to

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.