From f6c11e275687aa16664c4a15f57d7be591e41c16 Mon Sep 17 00:00:00 2001 From: "David Adam (zanchey)" Date: Wed, 30 Sep 2009 14:08:03 +0800 Subject: [PATCH] server.py: use Timer threads instead of single-threaded GLib timeouts --- server.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 25e8ff8..64752f5 100755 --- a/server.py +++ b/server.py @@ -11,6 +11,7 @@ import dbus, dbus.service import gobject from LATClient import LATClient from select import select +from threading import Timer def check_LAT_service(servicename, retries=3): latclient = LATClient(service=servicename.upper()) @@ -56,8 +57,12 @@ class Door(dbus.service.Object): object_path = '/au/asn/ucc/doors/%s' % doorname dbus.service.Object.__init__(self, bus, object_path) - # get initial state - self.poll() + # get initial state in a new thread + self.timeout = Timer(0, self.poll) + # daemon threads will be killed when the mainloop exits + # the timeout threads will inherit this value + self.timeout.setDaemon(True) + self.timeout.start() def poll(self): try: @@ -71,7 +76,8 @@ class Door(dbus.service.Object): self.status_changed(newstatus) # set up timeout again - gobject.timeout_add_seconds(self.interval, self.poll) + self.timeout = Timer(self.interval, self.poll) + self.timeout.start() @dbus.service.signal('au.asn.ucc.DoorInterface', signature='n') def status_changed(self, newstatus): @@ -83,6 +89,7 @@ class Door(dbus.service.Object): return self.status if __name__ == '__main__': + gobject.threads_init() doors = ('uccdoor', 'unisfadoor', 'chdoor', 'mrdoor', 'uccpir') from dbus.mainloop.glib import DBusGMainLoop -- 2.20.1