Skip to content

Commit

Permalink
Join worker processes in simulate_many()
Browse files Browse the repository at this point in the history
Although the worker processes are in daemon mode, and although we know
these daemon processes have posted their results to the result queue and
are thus done simulating, there still may be cleanup code that the
processes are running.

Specifically, this has been seen to effect coverage where coverage data
files can be partially written.
  • Loading branch information
jpgrayson committed Sep 7, 2017
1 parent c9283a9 commit 1eaa791
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions desmod/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,15 @@ def simulate_many(configs, top_type, env_type=SimEnvironment, jobs=None):
if jobs is not None:
num_workers = min(num_workers, jobs)

workers = []
for i in range(num_workers):
worker = Process(name='sim-worker-{}'.format(i),
target=_simulate_worker,
args=(top_type, env_type, False, progress_queue,
config_queue, result_queue))
worker.daemon = True # Workers die if main process dies.
worker.start()
workers.append(worker)
config_queue.put(None) # A stop sentinel for each worker.

if progress_enable:
Expand All @@ -312,6 +314,9 @@ def simulate_many(configs, top_type, env_type=SimEnvironment, jobs=None):
# progress_thread is still using it.
progress_thread.join(1)

for worker in workers:
worker.join(5)

return sorted(results, key=lambda r: r['config']['meta.sim.index'])


Expand Down

0 comments on commit 1eaa791

Please sign in to comment.