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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:11:40+00:00 2026-05-28T15:11:40+00:00

I have a User Interface that receives asynchronous notifications from a Service that prompts

  • 0

I have a User Interface that receives asynchronous notifications from a Service that prompts it to re-read information from a Database. The async notifications contain a primary key that can be used to retrieve the modified record. Under load, I might get 10 or 15 notifications a second, but frequently with duplicated IDs. Something like this:

{u'callback': u'job.modify', u'job-id': 1090, u'timestamp': u'2012-01-26 09:50:04.766'}
{u'callback': u'job.modify', u'job-id': 1091, u'timestamp': u'2012-01-26 09:50:04.767'}
{u'callback': u'job.modify', u'job-id': 1090, u'timestamp': u'2012-01-26 09:50:04.780'}
{u'callback': u'job.modify', u'job-id': 1091, u'timestamp': u'2012-01-26 09:50:04.808'}
{u'callback': u'job.modify', u'job-id': 1090, u'timestamp': u'2012-01-26 09:50:04.812'}
{u'callback': u'job.modify', u'job-id': 1090, u'timestamp': u'2012-01-26 09:50:04.829'}
{u'callback': u'job.modify', u'job-id': 1088, u'timestamp': u'2012-01-26 09:50:04.831'}
{u'callback': u'job.modify', u'job-id': 1088, u'timestamp': u'2012-01-26 09:50:04.836'}
{u'callback': u'job.modify', u'job-id': 1091, u'timestamp': u'2012-01-26 09:50:04.846'}

It would seem worthwhile to skip a few of the database reads in cases like this. I’m working with a class, so my thought was to configure some sort of refresh interval. This is what I have so far:

class myClass():
  def __init__(self):
    self.modified = set([])
    self.lastrefresh = datetime.datetime.now()
    self.refreshinterval = datetime.timedelta(milliseconds = 250)

  def onModify(self, data):
    self.modified.add(data['job-id'])
    if datetime.datetime.now() - self.lastrefresh < self.refreshinterval:
      return
    self.doModify()

  def doModify():
    ids = list(self.modified)
    self.lastrefresh = datetime.datetime.now()
    self.modified.clear()

Which works (mostly) but carries the potential to have a few updates left over. Because these updates are received async I never know how many or how often they’ll show up. Any pending refreshes are handled on the next notification, but if the next notification doesn’t come in a timely manner then ids sit in the modified set for much longer than the 250ms interval I want. Any suggestions are much appreciated.

  • 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-28T15:11:41+00:00Added an answer on May 28, 2026 at 3:11 pm

    I think I found a way to make this work. It requires the following modifications to the Class:

    class myClass():
      def __init__(self):
        self.modified = set([])
        self.lastrefresh = datetime.datetime.now()
        self.refreshinterval = datetime.timedelta(milliseconds = 250)
    
      def onModify(self, data):
        self.modified.add(data['job-id'])
        if datetime.datetime.now() - self.lastrefresh < self.refreshinterval:
          return
        self.doModify()
    
      def doModify():
        if not self.modified:
          return
        ids = list(self.modified)
        self.lastrefresh = datetime.datetime.now()
        self.modified.clear()
        wx.CallAfter(self.purgeModifies)
    
      def purgeModifies(self):
        wx.CallLater(250, self.doModify)
    

    It feels a little bit hokey to use wx.CallAfter and then immediately call wx.CallLater, but the onModify is happening in a background thread, which means that wx.CallLater throws a C++ Assertion Error. wx.CallAfter returns control to the Main Thread, which allows wx.CallLater to work. This gets me my “one more run” to handle any pending updates.

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

Sidebar

Related Questions

I have a fairly large application that uses WPF for its user interface. I
I have a user interface in .net which needs to receive data from a
I have a custom WinForms control (inherits from control, i.e. without user interface jsut
I have some SerialPort code that constantly needs to read data from a serial
I have a C# application with a user interface that contains options for the
I have a Delphi 6 application that receives and processes an image stream from
I have a function that presents the user a combo-box. def select_interface(interfaces) list_box :items
A lot of JavaScript libraries have user interface widgets. Usually they are created after
Applications which run on mobile devices have special user interface requirements. I think Apple
I have to make a graphical user interface application using the language of my

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.