示例#1
0
文件: child.py 项目: mct/kohorte
    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)
示例#2
0
文件: child.py 项目: mct/kohorte
    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
示例#3
0
文件: swarm.py 项目: mct/kohorte
    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()
示例#4
0
文件: connection.py 项目: mct/kohorte
    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)
示例#5
0
文件: proxy.py 项目: mct/kohorte
    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)
示例#6
0
文件: proxy.py 项目: mct/kohorte
    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()