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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:00:59+00:00 2026-06-12T20:00:59+00:00

I have the following code in a class: def __setattr__(self, key, value): self.__dict__[‘d’][key] =

  • 0

I have the following code in a class:

def __setattr__(self, key, value):
    self.__dict__['d'][key] = value
    ...
    self.saveToIni()

The saveToIni function saves all the dict’s items to an ini file at every object’s setattr call. If 80 setattr calls are made in the last 120ms, then the file will be written from scratch every time. The function also orders and sometimes deletes data from the dictonary, so I don’t want to change it.

I want to limit the calls to once in, let’s say, 5 seconds:

  1. When the first setattr is triggered, a timer starts asynchronicly, still not running saveToIni.
  2. If any calls are made to setattr and the timer is still counting, it will nor fire a timer nor run saveToIni.
  3. When the timer times out, the saveToIni should launch.

Now, I’m not sure how to achieve this behavoir. I’ve thought about messing with threads, but still didn’t found the idea about how to do it.

  • 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-12T20:01:00+00:00Added an answer on June 12, 2026 at 8:01 pm

    The way I would go, is to create a Timer Thread which runs a timedSaveToIni function once every 5 sec.
    I would also have a tag isSaveRequested telling this function if it should actually write data to the disk or not.

    The _setattr_ function would simply set this tag to true.

    Your code would look like this:

    class Dict:
    
      def __init__(self):
        ...
        self.isSaveRequested = False
        self.timedSaveToIni()
    
      def timedSaveToIni(self):
        threading.Timer(5.0, self.timedSaveToIni).start()
        if self.isSaveRequested:
          self.saveToIni()
          self.isSaveRequested = False
    
    
      def __setattr__(self, key, value):
        self.__dict__['d'][key] = value
        ...
        self.isSaveRequested = True
    
      def saveToInit()
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following python code: class FooMeta(type): def __setattr__(self, name, value): print name,
Let's say I have the following code: class MyClass(object): def __init__(self, param): self.param =
I am using Tornado and I have the following code: class UserHandler(RequestHandler): def get(self):
If I have the following piece of Ruby code: class Blah def self.bleh @blih
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
I have the following example code: class A(object): def __init__(self, id): self.myid = id
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
I have the following code. class person(object): def __init__(self, keys): for item in keys:
I have the following code : class C: def __init__(self, dx = 1): self._dx
I have following code: class EntityBase (object) : __entity__ = None def __init__ (self)

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.