Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7009f45

Browse files
author
Sean Quah
committed
Avoid waiting for zombie processes in synctl stop
1 parent a6f1a3a commit 7009f45

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

synctl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,24 @@ NORMAL = "\x1b[m"
4141
def pid_running(pid):
4242
try:
4343
os.kill(pid, 0)
44-
return True
4544
except OSError as err:
4645
if err.errno == errno.EPERM:
47-
return True
48-
return False
46+
pass # process exists
47+
else:
48+
return False
49+
50+
# When running in a container, orphan processes may not get reaped and their
51+
# PIDs may remain valid. Try to work around the issue.
52+
try:
53+
with open(f"/proc/{pid}/status") as status_file:
54+
if "zombie" in status_file.read():
55+
return False
56+
except Exception:
57+
# This isn't Linux or `/proc/` is unavailable.
58+
# Assume that the process is still running.
59+
pass
60+
61+
return True
4962

5063

5164
def write(message, colour=NORMAL, stream=sys.stdout):

0 commit comments

Comments
 (0)