From 61403f041918f443e5e4c074fb94dc87dfefd3c3 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Mon, 22 Jul 2024 23:20:46 -0600 Subject: [PATCH] Mods --- cromulant/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cromulant/main.py b/cromulant/main.py index 70250d9..5c5b5a4 100644 --- a/cromulant/main.py +++ b/cromulant/main.py @@ -1,5 +1,11 @@ from __future__ import annotations +import os +import sys +import fcntl +import tempfile +from pathlib import Path + from .config import Config from .utils import Utils from .ants import Ants @@ -11,6 +17,24 @@ from .filter import Filter def main() -> None: 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() Window.prepare() Ants.prepare()