michalsta / opentims

Open-source C++ and Python module for opening binary timsTOF data files.
Other
41 stars 11 forks source link

Closing file handle? #12

Closed jorainer closed 2 years ago

jorainer commented 2 years ago

Dear developers! First of all thanks for your great work. FYI, we've started to implement a "backend" for the Spectra package that would allow us to use/read TimsTOF data in Spectra that uses opentimsr for the actual i/o work.

When starting to code I was actually wondering if you could eventually also implement a close function for the object returned by OpenTIMS? I don't know what connections get all opened with the OpenTIMS, but it would be good to be also able to close all again to not run into errors from the operating system claiming that there are to many open file handles around.

michalsta commented 2 years ago

Hi,

For now all the file descriptors and everything used by OpenTIMS are cleanly and properly released when OpenTIMS object's destructor runs, which I guess is when the garbage collector decides to clean up the OpenTIMS object, so no long-term worries there. But...

For now, if you need file handles released immediately (because GC might not realize that OS is running short on file handles), then I guess (and sorry if there is a cleaner way to do this, but R is not my native language, so to speak ;) ), I guess you could explicitly destroy this object so its destructor is run (though... is it even possible to do that in R?) or do an rm(OpenTIMS handle) and then gc().

But yeah, I guess having an explicit close() method might be more idiomatic in R, so I'll try to implement this over the weekend ;)

jorainer commented 2 years ago

Thanks so much for the fast feedback! OK, so a rm might already do the trick - and the possible future dedicated close function might be even better :)

michalsta commented 2 years ago

OK, version 1.0.11 which is on CRAN with tests passed, contains (among other things) the CloseTIMS function, which releases all resources associated with TIMS handle. If you don't use it, the resources will still be cleanly and properly released when the garbage collector destroys the handle.