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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:31:51+00:00 2026-05-26T03:31:51+00:00

I’m starting out with DBus and event driven programming in general. The service that

  • 0

I’m starting out with DBus and event driven programming in general. The service that I’m trying to create really consists of three parts but two are really “server” things.

1) The actual DBus server talks to a remote website over HTTPS, manages sessions, and conveys info the clients.

2) The other part of the service calls a keep alive page every 2 minutes to keep the session active on the external website

3) The clients make calls to the service to retrieve info from the service.

I found some simple example programs. I’m trying to adapt them to prototype #1 and #2. Rather than building separate programs for both. I thought I that I can run them in a single, two threaded process.

The problem that I’m seeing is that I call time.sleep(X) in my keep alive thread. The thread goes to sleep, but won’t ever wake up. I think that the GIL isn’t released by the GLib main loop.

Here’s my thread code:

class Keepalive(threading.Thread):
  def __init__(self, interval=60):
    super(Keepalive, self).__init__()
    self.interval = interval
    bus = dbus.SessionBus()
    self.remote = bus.get_object("com.example.SampleService", "/SomeObject")

  def run(self):
    while True:
        print('sleep %i' % self.interval)
        time.sleep(self.interval)
        print('sleep done')
        reply_status = self.remote.keepalive()
        if reply_status:
            print('Keepalive: Success')
        else:
            print('Keepalive: Failure')

From the print statements, I know that the sleep starts, but I never see “sleep done.”

Here is the main code:

if __name__ == '__main__':
try:
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    session_bus = dbus.SessionBus()
    name = dbus.service.BusName("com.example.SampleService", session_bus)
    object = SomeObject(session_bus, '/SomeObject')

    mainloop = gobject.MainLoop()

    ka = Keepalive(15)
    ka.start()
    print('Begin main loop')
    mainloop.run()
except Exception as e:
    print(e)
finally:
    ka.join()

Some other observations:

I see the “begin main loop” message, so I know it’s getting control. Then, I see “sleep %i,” and after that, nothing.

If I ^C, then I see “sleep done.” After ~20 seconds, I get an exception from self.run() that the remote application didn’t respond:

DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

What’s the best way to run my keep alive code within the server?

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-05-26T03:31:51+00:00Added an answer on May 26, 2026 at 3:31 am

    You have to explicitly enable multithreading when using gobject by calling gobject.threads_init(). See the PyGTK FAQ for background info.

    Next to that, for the purpose you’re describing, timeouts seem to be a better fit. Use as follows:

    # Enable timer
    self.timer = gobject.timeout_add(time_in_ms, self.remote.keepalive)
    # Disable timer
    gobject.source_remove(self.timer)
    

    This calls the keepalive function every time_in_ms (milli)seconds. Further details, again, can be found at the PyGTK reference.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put

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.