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())
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:
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):
return self.status
if __name__ == '__main__':
+ gobject.threads_init()
doors = ('uccdoor', 'unisfadoor', 'chdoor', 'mrdoor', 'uccpir')
from dbus.mainloop.glib import DBusGMainLoop