From d65204febdb45300f195280955558099d600a7ee Mon Sep 17 00:00:00 2001 From: jand Date: Mon, 12 May 2003 23:36:08 +0000 Subject: [PATCH] refactor + clean-up cosimulation upon exception --- myhdl/Simulation.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/myhdl/Simulation.py b/myhdl/Simulation.py index 4c0cb0e0..58dcdc3f 100644 --- a/myhdl/Simulation.py +++ b/myhdl/Simulation.py @@ -75,6 +75,16 @@ class Simulation(object): warn("Cosimulation not registered as Simulation argument") del _futureEvents[:] del _siglist[:] + + + def finalize(self): + cosim = self._cosim + if cosim: + _simulator._cosim = 0 + os.close(cosim._rt) + os.close(cosim._wf) + os.waitpid(cosim._child_pid, 0) + def run(self, duration=None, quiet=0): @@ -165,19 +175,11 @@ class Simulation(object): except StopSimulation: if not quiet: printExcInfo() - if cosim: - _simulator._cosim = 0 - os.close(cosim._rt) - os.close(cosim._wf) - os.waitpid(cosim._child_pid, 0) + self.finalize() return 0 except: - if cosim: - _simulator._cosim = 0 - os.close(cosim._rt) - os.close(cosim._wf) - os.waitpid(cosim._child_pid, 0) + self.finalize() raise