import signal
import socket
from dispatcher import Dispatcher
-from eventloop import EventLoop
+from eventloop import EventLoop, LoopInterruptedError
class PyminDaemon(EventLoop):
r"""PyminDaemon(bind_addr, routes) -> PyminDaemon instance
# Signal handling
def quit(signum, frame):
print "Shuting down ..."
- loop.stop() # tell main event loop to stop
+ self.stop() # tell main event loop to stop
def reload_config(signum, frame):
print "Reloading configuration..."
# TODO iterate handlers list propagating reload action
def handle(self):
r"handle() -> None :: Handle incoming events using the dispatcher."
(msg, addr) = self.file.recvfrom(65535)
- self.dispatcher.dispatch(msg)
+ result = self.dispatcher.dispatch(msg)
+ if result is None:
+ msg = 'OK 0'
+ else:
+ msg = 'OK %d\n%s' % (len(str(result)), result)
+ self.file.sendto(msg, addr)
#try:
# d.dispatch(msg)
#except dis.BadRouteError, inst:
def run(self):
r"run() -> None :: Run the event loop (shortcut to loop())"
- return self.loop()
+ try:
+ return self.loop()
+ except LoopInterruptedError, e:
+ pass
if __name__ == '__main__':
+ @handler
def test_handler(*args):
print 'test:', args