From 7e4c062a13ae03203440e09734a822e30858d2c4 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 8 Nov 2023 10:23:06 +0100 Subject: [PATCH] set timeout --- player/player.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/player/player.py b/player/player.py index 6a434a1..3ebb87c 100755 --- a/player/player.py +++ b/player/player.py @@ -95,12 +95,11 @@ class Sync(Thread): self.adjust_position() if self._pos != self.mpv.playlist_current_pos: self._pos = self.mpv.playlist_current_pos - if self._pos != -1: - try: - track = self.mpv.playlist[self._pos] - logger.error("%s %s", datetime.now(), track["filename"]) - except: - pass + try: + track = self.mpv.playlist[self._pos] + logger.error("%s %s", datetime.now(), track["filename"]) + except: + pass def reload_playlist(self): if not self.reload_check: @@ -146,9 +145,14 @@ class Sync(Thread): # def read_position_main(self): - data = self.sock.recvfrom(1024)[0].decode().split(" ", 1) - self.main.time_pos = float(data[0]) - self.main.playlist_current_pos = int(data[1]) + self.sock.settimeout(5) + try: + data = self.sock.recvfrom(1024)[0].decode().split(" ", 1) + except socket.timeout: + logger.error("failed to receive data from main") + else: + self.main.time_pos = float(data[0]) + self.main.playlist_current_pos = int(data[1]) def adjust_position(self): if self.mpv.time_pos is not None: