Hopefully fixed lockup bug.

This commit is contained in:
Storm Dragon
2025-08-16 19:57:19 -04:00
parent 022b9ba048
commit c86921ea65
5 changed files with 228 additions and 111 deletions

30
util.py
View File

@@ -312,15 +312,29 @@ def get_media_duration(path):
command = ("ffprobe", "-v", "quiet", "-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1", path)
process = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE)
stdout, stderr = process.communicate()
try:
if not stderr:
return float(stdout)
else:
stdout, stderr = process.communicate(timeout=10) # Add timeout to prevent hanging
try:
if not stderr:
return float(stdout)
else:
return 0
except ValueError:
return 0
except ValueError:
except sp.TimeoutExpired:
process.kill()
process.wait()
return 0
finally:
# Ensure process is properly cleaned up
if process.poll() is None:
process.terminate()
try:
process.wait(timeout=2)
except sp.TimeoutExpired:
process.kill()
process.wait()
def parse_time(human):
@@ -405,9 +419,9 @@ def get_snapshot_version():
ver = "unknown"
if os.path.exists(os.path.join(root_dir, ".git")):
try:
ret = subprocess.check_output(["git", "describe", "--tags"]).strip()
ret = subprocess.check_output(["git", "describe", "--tags"], timeout=5).strip()
ver = ret.decode("utf-8")
except (FileNotFoundError, subprocess.CalledProcessError):
except (FileNotFoundError, subprocess.CalledProcessError, subprocess.TimeoutExpired):
try:
with open(os.path.join(root_dir, ".git/refs/heads/master")) as f:
ver = "g" + f.read()[:7]