示例#1
0
    def on_close(self):
        if self.process is None and self in sockets:
            sockets.remove(self)
            if shutting_down and len(sockets) == 0:
                # The last socket has been closed, now we can go
                IOLoop.current().stop()
        elif self.is_running():
            self.process.stop()

        if self.watched_game:
            self.watched_game.remove_watcher(self)

        if self.timeout:
            IOLoop.current().remove_timeout(self.timeout)

        if self.total_message_bytes == 0:
            comp_ratio = "N/A"
        else:
            comp_ratio = 100 - 100 * (
                self.compressed_bytes_sent +
                self.uncompressed_bytes_sent) / self.total_message_bytes
            comp_ratio = round(comp_ratio, 2)

        self.logger.info("Socket closed. (%s sent, compression ratio %s%%)",
                         util.humanise_bytes(self.total_message_bytes),
                         comp_ratio)
示例#2
0
 def test_humanise_bytes(self, num, expected):
     assert util.humanise_bytes(num) == expected