Browse Source

fixed freezing Dispatcher

master
Tom Krüger 4 years ago
parent
commit
7e76b12b65
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      al2/experiment.py

+ 12
- 3
al2/experiment.py View File

@ -51,21 +51,23 @@ 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))
waiter.start()
waiter.join()
if self.__stop_called.is_set():
for worker in self.__workers:
worker.terminate()
for worker in self.__workers:
worker.join()
@ -73,6 +75,13 @@ class Dispatcher (threading.Thread):
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)


Loading…
Cancel
Save