From 49e3d00fb36203be049e055aa6c0f4283d419c14 Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Tue, 28 Nov 2006 06:55:00 +0000 Subject: [PATCH] pyTivo - Stop the beacon should exit cleanly now --- beacon.py | 9 ++++++--- pyTivo.py | 7 +++++-- pyTivoService.py | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/beacon.py b/beacon.py index 13e7343..f6bbbb9 100644 --- a/beacon.py +++ b/beacon.py @@ -30,10 +30,13 @@ class Beacon(): def send_beacon(self): self.UDPSock.sendto(self.format_beacon(), ('255.255.255.255', 2190)) - def send_beacon_timer(self): + def start(self): self.send_beacon() - t = Timer(60, self.send_beacon_timer) - t.start() + self.timer = Timer(60, self.start) + self.timer.start() + + def stop(self): + self.timer.cancel() if __name__ == '__main__': b = Beacon() diff --git a/pyTivo.py b/pyTivo.py index 5bea24f..17c5b10 100644 --- a/pyTivo.py +++ b/pyTivo.py @@ -14,6 +14,9 @@ for section in config.sections(): b = beacon.Beacon() b.add_service('TiVoMediaServer:' + str(port) + '/http') -b.send_beacon_timer() +b.start() -httpd.serve_forever() +try: + httpd.serve_forever() +except KeyboardInterrupt: + b.stop() diff --git a/pyTivoService.py b/pyTivoService.py index 91ed6e1..0c4b25a 100644 --- a/pyTivoService.py +++ b/pyTivoService.py @@ -36,7 +36,7 @@ class PyTivoService(win32serviceutil.ServiceFramework): b = beacon.Beacon() b.add_service('TiVoMediaServer:' + str(port) + '/http') - b.send_beacon_timer() + b.start() while 1: sys.stdout.flush() @@ -45,6 +45,7 @@ class PyTivoService(win32serviceutil.ServiceFramework): sck.handle_request() rc = win32event.WaitForSingleObject(self.stop_event, 5) if rc == win32event.WAIT_OBJECT_0: + b.stop() break def SvcStop(self): -- 2.11.4.GIT