Skip to content

Commit

Permalink
check if thread is alive before closing
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Dec 24, 2024
1 parent fcb6c06 commit bf8c80e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion executorlib/base/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def shutdown(self, wait: bool = True, *, cancel_futures: bool = False):
"""
if cancel_futures:
cancel_items_in_queue(que=self._future_queue)
if self._process is not None:
if self._process is not None and self._process.is_alive():
self._future_queue.put({"shutdown": True, "wait": wait})
if wait:
self._process.join()
Expand Down
9 changes: 5 additions & 4 deletions executorlib/interactive/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ def shutdown(self, wait: bool = True, *, cancel_futures: bool = False):
if cancel_futures:
cancel_items_in_queue(que=self._future_queue)
if self._process is not None:
for _ in range(len(self._process)):
self._future_queue.put({"shutdown": True, "wait": wait})
for process in self._process:
if process.is_alive():
self._future_queue.put({"shutdown": True, "wait": wait})
if wait:
process.join()
if wait:
for process in self._process:
process.join()
self._future_queue.join()
self._process = None
self._future_queue = None
Expand Down

0 comments on commit bf8c80e

Please sign in to comment.