Skip to content

Commit

Permalink
Do not rely on is_alive
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Aug 12, 2024
1 parent bcb0d79 commit 092a79c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions salt/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,17 @@ def add(self, proc):

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)
Expand Down
3 changes: 3 additions & 0 deletions tests/pytests/functional/utils/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def target():

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()
Expand Down

0 comments on commit 092a79c

Please sign in to comment.