X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/b33b3ccf6aedaec3d33968d126131e3690319b90..2269d334bc9d3ae1c0de8229875b068e4cb29ac9:/pymindaemon.py?ds=sidebyside diff --git a/pymindaemon.py b/pymindaemon.py index 1e9589a..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())" @@ -80,6 +79,7 @@ class PyminDaemon(EventLoop): if __name__ == '__main__': + @handler def test_handler(*args): print 'test:', args