Commit ea9714c1 authored by peastman's avatar peastman
Browse files

CheckpointReporter does not create output file until first report

parent bb2d463c
...@@ -82,7 +82,8 @@ class CheckpointReporter(object): ...@@ -82,7 +82,8 @@ class CheckpointReporter(object):
self._reportInterval = reportInterval self._reportInterval = reportInterval
if isinstance(file, str): if isinstance(file, str):
self._own_handle = True self._own_handle = True
self._out = open(file, 'w+b', 0) self._filename = file
self._out = None
else: else:
self._out = file self._out = file
self._own_handle = False self._own_handle = False
...@@ -116,6 +117,8 @@ class CheckpointReporter(object): ...@@ -116,6 +117,8 @@ class CheckpointReporter(object):
state : State state : State
The current state of the simulation The current state of the simulation
""" """
if self._out is None:
self._out = open(self._filename, 'w+b', 0)
self._out.seek(0) self._out.seek(0)
chk = simulation.context.createCheckpoint() chk = simulation.context.createCheckpoint()
self._out.write(chk) self._out.write(chk)
...@@ -123,6 +126,6 @@ class CheckpointReporter(object): ...@@ -123,6 +126,6 @@ class CheckpointReporter(object):
self._out.flush() self._out.flush()
def __del__(self): def __del__(self):
if self._own_handle: if self._own_handle and self._out is not None:
self._out.close() self._out.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment