Exemplo n.º 1
0
    def close(self):
        if self.closed: return False  # Already closed
        self.closed = True
        self.connected = False
        self.event_connected.set(False)

        if config.debug_socket:
            self.log("Closing connection, waiting_requests: %s, buff: %s..." %
                     (len(self.waiting_requests), self.incomplete_buff_recv))
        for request in self.waiting_requests.values(
        ):  # Mark pending requests failed
            request.set(False)
        self.waiting_requests = {}
        self.server.removeConnection(
            self)  # Remove connection from server registry
        try:
            if self.forward_thread:
                self.forward_thread.kill(
                    exception=Debug.Notify("Closing connection"))
            if self.zmq_sock:
                self.zmq_sock.close()
            if self.sock:
                self.sock.shutdown(gevent.socket.SHUT_WR)
                self.sock.close()
        except Exception, err:
            if config.debug_socket:
                self.log("Close error: %s" % Debug.formatException(err))
Exemplo n.º 2
0
 def stop(self):
     self.manager.log.debug("%s: Force stopping" % self.key)
     self.running = False
     if self.thread:
         self.thread.kill(exception=Debug.Notify("Worker stopped"))
     del self.thread
     self.manager.removeWorker(self)
Exemplo n.º 3
0
 def skip(self, reason="Unknown"):
     self.manager.log.debug("%s: Force skipping (reason: %s)" %
                            (self.key, reason))
     if self.thread:
         self.thread.kill(
             exception=Debug.Notify("Worker skipping (reason: %s)" %
                                    reason))
     self.start()
Exemplo n.º 4
0
 def stop(self, reason="Unknown"):
     self.manager.log.debug("%s: Force stopping (reason: %s)" %
                            (self.key, reason))
     self.running = False
     if self.thread:
         self.thread.kill(
             exception=Debug.Notify("Worker stopped (reason: %s)" % reason))
     del self.thread
     self.manager.removeWorker(self)
Exemplo n.º 5
0
 def skip(self):
     self.manager.log.debug("%s: Force skipping" % self.key)
     if self.thread:
         self.thread.kill(exception=Debug.Notify("Worker stopped"))
     self.start()
Exemplo n.º 6
0
 def stopGreenlets(self, reason="Stopping all greenlets"):
     num = len(self.greenlets)
     gevent.killall(list(self.greenlets), Debug.Notify(reason), block=False)
     return num
Exemplo n.º 7
0
        if check_sites:  # Open port, Update sites, Check files integrity
            gevent.spawn(self.checkSites)

        thread_announce_sites = gevent.spawn(self.announceSites)
        thread_wakeup_watcher = gevent.spawn(self.wakeupWatcher)

        while self.running:
            try:
                ret = {}
                req = msgpack.unpackb(socket.recv())
                self.handleRequest(req)
            except Exception, err:
                self.log.error(err)
                if self.running:
                    self.socket.send(
                        msgpack.packb(
                            {"error": "%s" % Debug.formatException(err)},
                            use_bin_type=True))
                if config.debug:  # Raise exception
                    import sys
                    sys.modules["src.main"].DebugHook.handleError()
        thread_wakeup_watcher.kill(
            exception=Debug.Notify("Stopping FileServer"))
        thread_announce_sites.kill(
            exception=Debug.Notify("Stopping FileServer"))
        self.log.debug("Stopped.")

    def stop(self):
        self.running = False
        self.socket.close()