fixed freezing Dispatcher
This commit is contained in:
@@ -51,21 +51,23 @@ class Dispatcher (threading.Thread):
|
|||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
def wait_to_continue(workers, stop_called):
|
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)
|
time.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
waiter = threading.Thread(target=wait_to_continue,
|
waiter = threading.Thread(target=wait_to_continue,
|
||||||
args=(self.__workers,
|
args=(self.__workers,
|
||||||
self.__stop_called))
|
self.__stop_called))
|
||||||
|
|
||||||
waiter.start()
|
waiter.start()
|
||||||
waiter.join()
|
waiter.join()
|
||||||
|
|
||||||
if self.__stop_called.is_set():
|
if self.__stop_called.is_set():
|
||||||
for worker in self.__workers:
|
for worker in self.__workers:
|
||||||
worker.terminate()
|
worker.terminate()
|
||||||
|
|
||||||
|
|
||||||
for worker in self.__workers:
|
for worker in self.__workers:
|
||||||
worker.join()
|
worker.join()
|
||||||
@@ -73,6 +75,13 @@ class Dispatcher (threading.Thread):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
self.__stop_called.set()
|
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):
|
class Worker (multiprocessing.Process):
|
||||||
def __init__(self, exp_mod, exp_plan):
|
def __init__(self, exp_mod, exp_plan):
|
||||||
multiprocessing.Process.__init__(self)
|
multiprocessing.Process.__init__(self)
|
||||||
|
Reference in New Issue
Block a user