summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7461b0f)
This error is raised as a translation for the select.error, raised when
the system call is interrupted by a signal, so EventLoop users don't have
to know the details about the loop.
Please see EventLoop class documentation for more info.
"""
Please see EventLoop class documentation for more info.
"""
-from select import poll, POLLIN, POLLPRI, POLLERR
+import select
+from select import POLLIN, POLLPRI, POLLERR
+class LoopInterruptedError(RuntimeError):
+ def __init__(self, select_error):
+ self.select_error = select_error
+ def __repr__(self):
+ return 'LoopInterruptedError(select_error=%r)' % self.select_error
+ def __str__(self):
+ return 'Loop interrupted: %s' % self.select_error
+
class EventLoop:
r"""EventLoop(file[, handler]) -> EventLoop instance
class EventLoop:
r"""EventLoop(file[, handler]) -> EventLoop instance
See EventLoop class documentation for more info.
"""
See EventLoop class documentation for more info.
"""
+ self.poll = select.poll()
self._stop = False
self.__register(file)
self.handler = handler
self._stop = False
self.__register(file)
self.handler = handler
then only 1 event is processed and then this method returns.
"""
while True:
then only 1 event is processed and then this method returns.
"""
while True:
+ try:
+ res = self.poll.poll()
+ except select.error, e:
+ raise LoopInterruptedError(e)
if self.handler is not None:
self.handler(self)
else:
if self.handler is not None:
self.handler(self)
else:
import signal
import socket
from dispatcher import Dispatcher
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
class PyminDaemon(EventLoop):
r"""PyminDaemon(bind_addr, routes) -> PyminDaemon instance
def run(self):
r"run() -> None :: Run the event loop (shortcut to loop())"
def run(self):
r"run() -> None :: Run the event loop (shortcut to loop())"
+ try:
+ return self.loop()
+ except LoopInterruptedError, e:
+ pass
if __name__ == '__main__':
if __name__ == '__main__':