Skip to content

Commit

Permalink
Update comments and _terminate_tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
PeiwenGaoMS committed Mar 7, 2024
1 parent d542803 commit bbb54ca
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def start(self):

def close(self):
"""End the process pool and close the thread pool."""
# Put n (equal to processes number) terminate signals to the task queue to ensure each thread receives one.
# Terminate the task of monitor threads.
self._terminate_tasks()
# Close the thread pool and wait for all threads to complete.
if self._monitor_pool is not None:
Expand Down Expand Up @@ -410,9 +410,11 @@ def _all_tasks_ready(self):
return all(async_task.ready() for async_task in self._async_tasks)

def _terminate_tasks(self):
if not self._all_tasks_ready():
for _ in range(self._n_process):
self._task_queue.put(TERMINATE_SIGNAL)
if self._all_tasks_ready():
return
# Put n (equal to processes number) terminate signals to the task queue to ensure each thread receives one.
for _ in range(self._n_process):
self._task_queue.put(TERMINATE_SIGNAL)

def _determine_worker_count(self, worker_count):
# Starting a new process in non-fork mode requires to allocate memory.
Expand Down

0 comments on commit bbb54ca

Please sign in to comment.