fixed freezing Dispatcher
This commit is contained in:
@@ -51,11 +51,12 @@ class Dispatcher (threading.Thread):
|
||||
worker.start()
|
||||
|
||||
def wait_to_continue(workers, stop_called):
|
||||
any_worker_alive = any(map(lambda w: w.is_alive(), workers))
|
||||
any_worker_alive = lambda: any(map(lambda w: w.is_alive(), workers))
|
||||
|
||||
while any_worker_alive and not stop_called.is_set():
|
||||
while any_worker_alive() and not stop_called.is_set():
|
||||
time.sleep(0)
|
||||
|
||||
|
||||
waiter = threading.Thread(target=wait_to_continue,
|
||||
args=(self.__workers,
|
||||
self.__stop_called))
|
||||
@@ -67,12 +68,20 @@ class Dispatcher (threading.Thread):
|
||||
for worker in self.__workers:
|
||||
worker.terminate()
|
||||
|
||||
|
||||
for worker in self.__workers:
|
||||
worker.join()
|
||||
|
||||
def stop(self):
|
||||
self.__stop_called.set()
|
||||
|
||||
def num_active_workers(self):
|
||||
count = 0
|
||||
for worker in self.__workers:
|
||||
count += 1 if worker.is_alive() else 0
|
||||
|
||||
return count
|
||||
|
||||
class Worker (multiprocessing.Process):
|
||||
def __init__(self, exp_mod, exp_plan):
|
||||
multiprocessing.Process.__init__(self)
|
||||
|
Reference in New Issue
Block a user