Exemple #1
0
    def on_readable(self):
        buf = self.fd.read(1024)

        if buf:
            for line in buf.split('\n'):
                if line == '':
                    continue
                print timestamp(), self, repr(line.rstrip())
            return

        #print timestamp(), self, "EOF"

        # If we waitpid() with os.WNOHANG, sometimes our waitpid() syscall will
        # execute before our child process has had a chance to exit(), in which
        # case it returns the PID as 0.  As we can be reasonably assured that
        # the child will exit soon now that it has closed sdout, let's risk
        # blocking.

        #(pid, exitcode) = os.waitpid(self.pid, os.WNOHANG)
        (pid, exitcode) = os.waitpid(self.pid, 0)
        assert pid == self.pid

        print timestamp(), self, "exit", exitcode
        self.exitcode = exitcode
        self.closed = True
        EventLoop.unregister(self)
Exemple #2
0
    def close(self):
        if self.closed:
            return
        self.closed = True

        print timestamp(), self, "I was asked to close?  Ok..."
        EventLoop.unregister(self)

        try:
            self.fd.close()
            os.killpg(self.pid, signal.SIGTERM)
            self.popen.wait()
        except Exception:
            traceback.print_exc()
            print
Exemple #3
0
    def drop(self):
        if self.closed:
            return
        self.closed = True

        del self.index[self.sha]
        EventLoop.unregister(self)

        print timestamp(), self, "Dropping (and %d peers)" % len(self.peers)

        # We need to make a copy of self.peers, because when peers are closed,
        # they'll be modifying the list as we iterate through it.  This was a
        # an *extremely* annoying bug to track down.
        for x in list(self.peers):
            print "Closing", x
            x.close()
Exemple #4
0
    def close(self):
        if self.closed:
            return
        self.closed = True

        print timestamp(), self, "Closing Connection"

        try:
            self.sock.close()
        except Exception:
            traceback.print_exc()

        try:
            self.peer.close()
        except Exception:
            traceback.print_exc()

        EventLoop.unregister(self)
Exemple #5
0
    def close(self):
        if self.closed:
            return
        self.closed = True

        #print timestamp(), self, "Closing"

        try:
            self.sock.close()
        except Exception:
            traceback.print_exc()

        if self.eof:
            self.peer.proxy_close(self, cancel=False)
        else:
            self.peer.proxy_close(self, cancel=True)

        EventLoop.unregister(self)
Exemple #6
0
    def close(self):
        if self.closed:
            return
        self.closed = True

        self.reap_children()
        if self.children:
            print timestamp(), self, "Shutting down, but still children:", self.children

        try:
            self.sock.close()
        except Exception:
            traceback.print_exc()

        EventLoop.unregister(self)

        for x in self.children:
            if not x.closed:
                x.close()