Skip to content

Commit c423644

Browse files
thomassedlmayerpmai
authored andcommitted
Minor changes
Signed-off-by: Thomas Sedlmayer <tsedlmayer@pmsfit.de>
1 parent adc1cad commit c423644

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

osi3trace/osi_trace.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def __init__(self, path, topic):
312312
self.path = Path(path)
313313
self._file = open(self.path, "rb")
314314
self.mcap_reader = make_reader(self._file, decoder_factories=[DecoderFactory()])
315+
self._iter = None
315316
self._summary = self.mcap_reader.get_summary()
316317
available_topics = self.get_available_topics()
317318
if topic == None:
@@ -323,18 +324,22 @@ def __init__(self, path, topic):
323324
def restart(self, index=None):
324325
if index != None:
325326
raise NotImplementedError("Restarting from a given index is not supported for multi-channel traces.")
326-
if hasattr(self, "_iter"):
327-
del self._iter
327+
self._iter = None
328328

329329
def __iter__(self):
330330
"""Stateful iterator over the channel's messages in log time order."""
331-
if not hasattr(self, "_iter"):
331+
if self._iter is None:
332332
self._iter = self.mcap_reader.iter_decoded_messages(topics=[self.topic])
333333
for message in self._iter:
334334
yield message.decoded_message
335335

336336
def close(self):
337-
self._file.close()
337+
if self._file:
338+
self._file.close()
339+
self._file = None
340+
self.mcap_reader = None
341+
self._summary = None
342+
self._iter = None
338343

339344
def get_available_topics(self):
340345
return [channel.topic for id, channel in self._summary.channels.items()]

0 commit comments

Comments
 (0)