Do not rely on is_alive

This commit is contained in:
Daniel A. Wozniak 2024-08-07 00:37:59 -07:00 committed by Daniel Wozniak
parent bcb0d79cdc
commit 092a79ccb9
2 changed files with 13 additions and 6 deletions

View file

@ -1169,13 +1169,17 @@ class SubprocessList:
def cleanup(self):
with self.lock:
for proc in self.processes:
if proc.is_alive():
continue
proc.join()
# Only processes have a close method, threads do not.
if hasattr(proc, "close"):
for proc in self.processes[:]:
proc.join(0.01)
if hasattr(proc, "exitcode"):
# Only processes have exitcode and a close method, threads
# do not.
if proc.exitcode is None:
continue
proc.close()
else:
if proc.is_alive():
continue
self.processes.remove(proc)
self.count -= 1
log.debug("Subprocess %s cleaned up", proc.name)

View file

@ -58,7 +58,10 @@ def test_subprocess_list_fds():
process = salt.utils.process.SignalHandlingProcess(target=target)
process.start()
process_list.add(process)
time.sleep(0.3)
num = _get_num_fds(pid)
assert num == before_num + 2
start = time.time()