X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/fbb90886873a6430d44ba2c9e1cfc8ab9d7f14c4..d6d7ebf986963fbf1d960730b7371ee5bbbf2952:/pymindaemon.py?ds=sidebyside diff --git a/pymindaemon.py b/pymindaemon.py index 1ddef6c..b8369b9 100644 --- a/pymindaemon.py +++ b/pymindaemon.py @@ -58,18 +58,17 @@ class PyminDaemon(EventLoop): def handle(self): r"handle() -> None :: Handle incoming events using the dispatcher." (msg, addr) = self.file.recvfrom(65535) - result = self.dispatcher.dispatch(msg) + try: + result = self.dispatcher.dispatch(msg) + response = 'OK ' + except Exception, e: + result = str(e) + response = 'ERROR ' if result is None: - msg = 'OK 0' + response += '0' else: - msg = 'OK %d\n%s' % (len(str(result)), result) - self.file.sendto(msg, addr) - #try: - # d.dispatch(msg) - #except dis.BadRouteError, inst: - # sock.sendto('Bad route from : ' + inst.cmd + '\n', addr) - #except dis.CommandNotFoundError, inst: - # sock.sendto('Command not found : ' + inst.cmd + '\n', addr) + response += '%d\n%s' % (len(str(result)), result) + self.file.sendto(response, addr) def run(self): r"run() -> None :: Run the event loop (shortcut to loop())"