From 741cb44a479a78976c2f7c527c9eda1d2637096a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=AC=E9=80=8D=E9=81=A5?= <1666871743@qq.com> Date: Sun, 5 Jul 2020 11:43:07 -0400 Subject: [PATCH] Solve the problem of high CPU occupation I found that if video_socket is set to blocking mode, the CPU usage will drop significantly. Therefore, the corresponding acceptance code should also be modified appropriately. --- viewer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/viewer.py b/viewer.py index f019f73..0af738d 100644 --- a/viewer.py +++ b/viewer.py @@ -85,7 +85,7 @@ def init_server_connection(self): res = self.video_socket.recv(4) self.resolution = struct.unpack(">HH", res) logger.info("Screen resolution: %s", self.resolution) - self.video_socket.setblocking(False) + self.video_socket.setblocking(True) def deploy_server(self, max_width=1024, bitrate=8000000, max_fps=0): try: @@ -131,6 +131,8 @@ def get_next_frames(self): try: raw_h264 = self.video_socket.recv(0x10000) + if(raw_h264 == b''): + return None packets = self.codec.parse(raw_h264) if not packets: