Implement single instance check with lock file

Add single_instance function to prevent multiple instances.
This commit is contained in:
Roy
2026-06-11 18:46:02 -07:00
committed by GitHub
parent 07c1dc88e6
commit b6aaff2959
+12
View File
@@ -38,7 +38,19 @@ from urllib.parse import (
quote quote
) )
LOCK_FILE = "/tmp/nslgamescanner.lock"
def single_instance():
global lockfile
lockfile = open(LOCK_FILE, "w")
try:
fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
print("Another instance is already running. Exiting.")
sys.exit(0)
single_instance()
# Check the value of the DBUS_SESSION_BUS_ADDRESS environment variable # Check the value of the DBUS_SESSION_BUS_ADDRESS environment variable