Fixed sleep inhibition error

This commit is contained in:
Deniz Şafak
2025-08-25 02:19:05 +03:00
parent 528343f375
commit aa98547456
2 changed files with 21 additions and 11 deletions
+19 -11
View File
@@ -3,6 +3,7 @@ import sys
import json
import warnings
import platform
import shutil
import subprocess
import re
from threading import Thread
@@ -286,17 +287,24 @@ def prevent_sleep_start():
# Add program name and reason for inhibition
program_name = PROGRAM_NAME
reason = "Prevent sleep during abogen process"
_sleep_procs["Linux"] = create_process(
[
"systemd-inhibit",
f"--who={program_name}",
f"--why={reason}",
"--what=sleep",
"--mode=block",
"sleep",
"infinity",
]
)
# Only attempt to use systemd-inhibit if it's available on the system.
if shutil.which("systemd-inhibit"):
_sleep_procs["Linux"] = create_process(
[
"systemd-inhibit",
f"--who={program_name}",
f"--why={reason}",
"--what=sleep",
"--mode=block",
"sleep",
"infinity",
]
)
else:
# Non-systemd distro or systemd tools not installed: skip inhibition rather than crash
print(
"systemd-inhibit not found: skipping sleep inhibition on this Linux system."
)
def prevent_sleep_end():