Merge pull request #9572 from LabNConsulting/chopps/fix-cleanup

tests: deal with parallel exit of process we are reaping
This commit is contained in:
Mark Stapp 2021-09-08 12:26:51 -04:00 committed by GitHub
commit 75ec7bdb5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,8 +33,11 @@ def get_pids_with_env(has_var, has_val=None):
result = {} result = {}
for pidenv in glob.iglob("/proc/*/environ"): for pidenv in glob.iglob("/proc/*/environ"):
pid = pidenv.split("/")[2] pid = pidenv.split("/")[2]
try:
with open(pidenv, "rb") as rfb: with open(pidenv, "rb") as rfb:
envlist = [x.decode("utf-8").split("=", 1) for x in rfb.read().split(b"\0")] envlist = [
x.decode("utf-8").split("=", 1) for x in rfb.read().split(b"\0")
]
envlist = [[x[0], ""] if len(x) == 1 else x for x in envlist] envlist = [[x[0], ""] if len(x) == 1 else x for x in envlist]
envdict = dict(envlist) envdict = dict(envlist)
if has_var not in envdict: if has_var not in envdict:
@ -43,6 +46,9 @@ def get_pids_with_env(has_var, has_val=None):
result[pid] = envdict result[pid] = envdict
elif envdict[has_var] == str(has_val): elif envdict[has_var] == str(has_val):
result[pid] = envdict result[pid] = envdict
except Exception:
# E.g., process exited and files are gone
pass
return result return result