コード例 #1
0
ファイル: core.py プロジェクト: timdoug/diesel
    def run(self):
        from diesel.app import ApplicationEnd
        self.running = True
        self.app.running.add(self)
        try:
            self.loop_callable(*self.args, **self.kw)
        except TerminateLoop:
            pass
        except (SystemExit, KeyboardInterrupt, ApplicationEnd):
            raise
        except ParentDiedException:
            pass
        except:
            log.error("-- Unhandled Exception in local loop <%s> --" % self.loop_label)
            log.error(traceback.format_exc())
        finally:
            if self.connection_stack:
                assert len(self.connection_stack) == 1
                self.connection_stack.pop().close()
        self.running = False
        self.app.running.remove(self)
        self.notify_children()
        if self.parent and self in self.parent.children:
            self.parent.children.remove(self)
            self.parent = None

        if self.keep_alive:
            log.warn("(Keep-Alive loop %s died; restarting)" % self)
            self.reset()
            self.hub.call_later(0.5, self.wake)
コード例 #2
0
    def run(self):
        from diesel.app import ApplicationEnd
        self.running = True
        self.app.running.add(self)
        try:
            self.loop_callable(*self.args, **self.kw)
        except TerminateLoop:
            pass
        except (SystemExit, KeyboardInterrupt, ApplicationEnd):
            raise
        except:
            log.error("-- Unhandled Exception in local loop <%s> --" %
                      self.loop_label)
            log.error(traceback.format_exc())
        finally:
            if self.connection_stack:
                assert len(self.connection_stack) == 1
                self.connection_stack.pop().close()
        self.running = False
        self.app.running.remove(self)
        self.notify_children()
        if self.parent and self in self.parent.children:
            self.parent.children.remove(self)
            self.parent = None

        if self.keep_alive:
            log.warn("(Keep-Alive loop %s died; restarting)" % self)
            self.reset()
            self.hub.call_later(0.5, self.wake)
コード例 #3
0
        def read_callback():
            # DJB on handling socket connection failures, from
            # http://cr.yp.to/docs/connect.html

            # "Another possibility is getpeername(). If the socket is
            # connected, getpeername() will return 0. If the socket is not
            # connected, getpeername() will return ENOTCONN, and read(fd,&ch,1)
            # will produce the right errno through error slippage. This is a
            # combination of suggestions from Douglas C. Schmidt and Ken Keys."

            try:
                sock.getpeername()
            except socket.error:
                try:
                    d = sock.recv(1)
                except socket.error, e:
                    if e.errno == errno.ECONNREFUSED:
                        d = ''
                    else:
                        d = None

                if d != '':
                    log.error(
                        "internal error: expected empty read on disconnected socket"
                    )

                if cancel_timer is not None:
                    cancel_timer.cancel()
                self.hub.unregister(sock)
                self.hub.schedule(lambda: self.wake(
                    ClientConnectionError(
                        "Could not connect to remote host (%s:%s)" %
                        (host, port))))
                return
コード例 #4
0
ファイル: core.py プロジェクト: 1angxi/diesel
        def read_callback():
            # DJB on handling socket connection failures, from
            # http://cr.yp.to/docs/connect.html

            # "Another possibility is getpeername(). If the socket is
            # connected, getpeername() will return 0. If the socket is not
            # connected, getpeername() will return ENOTCONN, and read(fd,&ch,1)
            # will produce the right errno through error slippage. This is a
            # combination of suggestions from Douglas C. Schmidt and Ken Keys."

            try:
                sock.getpeername()
            except socket.error:
                try:
                    d = sock.recv(1)
                except socket.error, e:
                    if e.errno == errno.ECONNREFUSED:
                        d = ''
                    else:
                        d = None

                if d != '':
                    log.error("internal error: expected empty read on disconnected socket")

                if cancel_timer is not None:
                    cancel_timer.cancel()
                self.hub.unregister(sock)
                self.hub.schedule(
                lambda: self.wake(
                    ClientConnectionError("Could not connect to remote host (%s:%s)" % (host, port))
                    ))
                return
コード例 #5
0
    def run(self):
        """Start up an Application--blocks until the program ends
        or .halt() is called.
        """
        self._run = True
        logmod.set_current_application(self)
        log.info("Starting diesel application")

        for s in self._services:
            s.bind_and_listen()
            self.hub.register(s.sock, s.accept_new_connection, None)
        for l in self._loops:
            l.iterate()

        self.setup()
        while self._run:
            try:
                self.hub.handle_events()
            except SystemExit:
                log.warn("-- SystemExit raised.. exiting main loop --")
                break
            except KeyboardInterrupt:
                log.warn("-- KeyboardInterrupt raised.. exiting main loop --")
                break
            except Exception, e:
                log.error("-- Unhandled Exception in main loop --")
                log.error(traceback.format_exc())
コード例 #6
0
ファイル: app.py プロジェクト: timdoug/diesel
 def main():
     while self._run:
         try:
             self.hub.handle_events()
         except SystemExit:
             log.warn("-- SystemExit raised.. exiting main loop --")
             break
         except KeyboardInterrupt:
             log.warn("-- KeyboardInterrupt raised.. exiting main loop --")
             break
         except ApplicationEnd:
             log.warn("-- ApplicationEnd raised.. exiting main loop --")
             break
         except Exception, e:
             log.error("-- Unhandled Exception rose to main loop --")
             log.error(traceback.format_exc())
コード例 #7
0
ファイル: app.py プロジェクト: wmoss/diesel
 def main():
     while self._run:
         try:
             self.hub.handle_events()
         except SystemExit:
             log.warn("-- SystemExit raised.. exiting main loop --")
             break
         except KeyboardInterrupt:
             log.warn(
                 "-- KeyboardInterrupt raised.. exiting main loop --")
             break
         except ApplicationEnd:
             log.warn("-- ApplicationEnd raised.. exiting main loop --")
             break
         except Exception, e:
             log.error("-- Unhandled Exception rose to main loop --")
             log.error(traceback.format_exc())
コード例 #8
0
ファイル: core.py プロジェクト: viraptor/diesel
 def run(self):
     from diesel.app import ApplicationEnd
     try:
         self.loop_callable(*self.args, **self.kw)
     except (SystemExit, KeyboardInterrupt, ApplicationEnd):
         raise
     except:
         log.error("-- Unhandled Exception in local loop --")
         log.error(traceback.format_exc())
     finally:
         if self.connection_stack:
             assert len(self.connection_stack) == 1
             self.connection_stack.pop().close()
     if self.keep_alive:
         log.warn("(Keep-Alive loop %s died; restarting)" % self)
         self.reset()
         self.hub.call_later(0.5, self.wake)
コード例 #9
0
ファイル: app.py プロジェクト: mvaled/diesel
        def _main():
            while self._run:
                try:
                    self.hub.handle_events()
                except SystemExit:
                    log.warning("-- SystemExit raised.. exiting main loop --")
                    raise
                except KeyboardInterrupt:
                    log.warning("-- KeyboardInterrupt raised.. exiting main loop --")
                    break
                except ApplicationEnd:
                    log.warning("-- ApplicationEnd raised.. exiting main loop --")
                    break
                except Exception:
                    log.error("-- Unhandled Exception rose to main loop --")
                    log.error(traceback.format_exc())

            log.info('Ending diesel application')
            runtime.current_app = None
コード例 #10
0
ファイル: core.py プロジェクト: edahlgren/diesel
        def read_callback():
            try:
                sock.getpeername()
            except socket.error:
                try:
                    d = sock.recv(1)
                except:
                    d = None

                if d != '':
                    log.error("internal error: expected empty read on disconnected socket")

                if cancel_timer is not None:
                    cancel_timer.cancel()
                self.hub.unregister(sock)
                self.hub.schedule(
                lambda: self.wake(
                    ClientConnectionError("Could not connect to remote host (%s:%s)" % (host, port))
                    ))
                return
コード例 #11
0
        def read_callback():
            try:
                sock.getpeername()
            except socket.error:
                try:
                    d = sock.recv(1)
                except:
                    d = None

                if d != '':
                    log.error("internal error: expected empty read on disconnected socket")

                if cancel_timer is not None:
                    cancel_timer.cancel()
                self.hub.unregister(sock)
                self.hub.schedule(
                lambda: self.wake(
                    ClientConnectionError("Could not connect to remote host (%s:%s)" % (host, port))
                    ))
                return