https://github.com/Atoptool/atop/pull/345 From aae92fe43b4f3577d7bf84f347514e432071f282 Mon Sep 17 00:00:00 2001 From: "Z. Liu" Date: Thu, 24 Jul 2025 11:47:10 +0800 Subject: [PATCH 1/2] atopgpud: fork before any thread action since python 3.12, os.fork now raise a DeprecationWarning, see https://docs.python.org/3/whatsnew/3.12.html#deprecated: > /usr/bin/atopgpud:283: DeprecationWarning: This process (pid=64696) > is multi-threaded, use of fork() may lead to deadlocks in the child. so let's fork as early as possible, before any thread action (gpulock & "import pynvml"). Signed-off-by: Z. Liu diff --git a/atopgpud b/atopgpud index 84517fe..4f8f0e5 100755 --- a/atopgpud +++ b/atopgpud @@ -66,7 +66,7 @@ cliterm = {} # dict with one entry per client (client # that still have to be received by this client # (pid of terminated process as key) -gpulock = threading.Lock() # mutex for access to gpulist/cliterm +gpulock = None # ================================= @@ -275,15 +275,8 @@ def main(): logging.error("Socket binding to port %d fails", GPUDPORT) sys.exit(1) - # ----------------------------- - # release parent process - # (daemonize) - # ----------------------------- - try: - if os.fork(): - sys.exit(0) # parent process exits; child continues... - except Exception: - logging.error("Failed to fork child") + global gpulock + gpulock = threading.Lock() # mutex for access to gpulist/cliterm # ----------------------------- # initialize GPU access for the @@ -589,6 +582,16 @@ lg = logging.getLogger() # root logger lg.addHandler(fh) lg.setLevel(loglevel) +# ----------------------------- +# release parent process +# (daemonize) +# ----------------------------- +try: + if os.fork(): + sys.exit(0) # parent process exits; child continues... +except Exception: + logging.error("Failed to fork child") + # ----------------------------- # load module pynvml # ----------------------------- -- 2.45.2 From 1a226186868d806809cc8486eae46f5df28290b6 Mon Sep 17 00:00:00 2001 From: "Z. Liu" Date: Thu, 24 Jul 2025 17:31:44 +0800 Subject: [PATCH 2/2] atopgpud: don't daemonize if has arg "-f" so we can handle it by openrc Signed-off-by: Z. Liu diff --git a/atopgpud b/atopgpud index 4f8f0e5..a0e9a3f 100755 --- a/atopgpud +++ b/atopgpud @@ -582,15 +582,16 @@ lg = logging.getLogger() # root logger lg.addHandler(fh) lg.setLevel(loglevel) -# ----------------------------- -# release parent process -# (daemonize) -# ----------------------------- -try: - if os.fork(): - sys.exit(0) # parent process exits; child continues... -except Exception: - logging.error("Failed to fork child") +if '-f' not in sys.argv: + # ----------------------------- + # release parent process + # (daemonize) + # ----------------------------- + try: + if os.fork(): + sys.exit(0) # parent process exits; child continues... + except Exception: + logging.error("Failed to fork child") # ----------------------------- # load module pynvml -- 2.45.2