1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
https://github.com/Atoptool/atop/pull/345
From aae92fe43b4f3577d7bf84f347514e432071f282 Mon Sep 17 00:00:00 2001
From: "Z. Liu" <zhixu.liu@gmail.com>
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 <zhixu.liu@gmail.com>
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" <zhixu.liu@gmail.com>
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 <zhixu.liu@gmail.com>
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
|