How to implement a watchdog timer in Python?

Just publishing my own solution to this: from threading import Timer class Watchdog(Exception): def __init__(self, timeout, userHandler=None): # timeout in seconds self.timeout = timeout self.handler = userHandler if userHandler is not None else self.defaultHandler self.timer = Timer(self.timeout, self.handler) self.timer.start() def reset(self): self.timer.cancel() self.timer = Timer(self.timeout, self.handler) self.timer.start() def stop(self): self.timer.cancel() def defaultHandler(self): raise self Usage … Read more

How can I verify if a Windows Service is running

I guess something like this would work: Add System.ServiceProcess to your project references (It’s on the .NET tab). using System.ServiceProcess; ServiceController sc = new ServiceController(SERVICENAME); switch (sc.Status) { case ServiceControllerStatus.Running: return “Running”; case ServiceControllerStatus.Stopped: return “Stopped”; case ServiceControllerStatus.Paused: return “Paused”; case ServiceControllerStatus.StopPending: return “Stopping”; case ServiceControllerStatus.StartPending: return “Starting”; default: return “Status Changing”; } Edit: There … Read more