This commit is contained in:
Auric Vente 2024-07-22 23:20:46 -06:00
parent a7904d3dff
commit 61403f0419
1 changed files with 24 additions and 0 deletions

View File

@ -1,5 +1,11 @@
from __future__ import annotations from __future__ import annotations
import os
import sys
import fcntl
import tempfile
from pathlib import Path
from .config import Config from .config import Config
from .utils import Utils from .utils import Utils
from .ants import Ants from .ants import Ants
@ -11,6 +17,24 @@ from .filter import Filter
def main() -> None: def main() -> None:
Config.prepare() Config.prepare()
program = Config.manifest["program"]
title = Config.manifest["title"]
pid = f"{program}.pid"
pid_file = Path(tempfile.gettempdir(), pid)
fp = pid_file.open("w", encoding="utf-8")
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
Utils.print(f"{title} is already running.")
sys.exit(0)
# Create singleton
fp.write(str(os.getpid()))
fp.flush()
Utils.prepare() Utils.prepare()
Window.prepare() Window.prepare()
Ants.prepare() Ants.prepare()