From a430c1d4a37c07328d30e37de15d077c90dc0aa5 Mon Sep 17 00:00:00 2001 From: Wanda Date: Tue, 27 Feb 2024 04:10:41 +0100 Subject: [PATCH] sim.pysim: Only close VCD/GTKW files if we opened them ourselves. Fixes #1107. --- amaranth/sim/pysim.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/amaranth/sim/pysim.py b/amaranth/sim/pysim.py index a077d1e30..8cc975477 100644 --- a/amaranth/sim/pysim.py +++ b/amaranth/sim/pysim.py @@ -40,10 +40,14 @@ def __init__(self, fragment, *, vcd_file, gtkw_file=None, traces=()): # the simulator is still usable if it's not installed for some reason. import vcd, vcd.gtkw + self.close_vcd = False + self.close_gtkw = False if isinstance(vcd_file, str): vcd_file = open(vcd_file, "w") + self.close_vcd = True if isinstance(gtkw_file, str): gtkw_file = open(gtkw_file, "w") + self.close_gtkw = True self.vcd_vars = SignalDict() self.vcd_file = vcd_file @@ -150,9 +154,9 @@ def close(self, timestamp): for name in self.gtkw_names[signal]: self.gtkw_save.trace(name) - if self.vcd_file is not None: + if self.close_vcd: self.vcd_file.close() - if self.gtkw_file is not None: + if self.close_gtkw: self.gtkw_file.close()