MideTechnology / endaq-python

A comprehensive, user-centric Python API for working with enDAQ data and devices
MIT License
24 stars 12 forks source link

ide file remains in use after get_doc #209

Closed oridatt closed 1 year ago

oridatt commented 1 year ago

I used the library to read several ide files. I then found these files were still "in use" after my script had completed.

StokesMIDE commented 1 year ago

This is the expected behavior; in the underlying idelib package, IDE files are read dynamically (lazy loaded), so they remain open.

There are two solutions: either explicitly close the files with the method Dataset.close() after using the file, or use a with context block. An example of the latter:

import endaq

with endaq.ide.files.get_doc('myfile.ide') as doc:
    print(doc.closed)  # "False"
    ct = endaq.ide.info.get_channel_table(doc)

print(doc.closed)  # "True"