bio-phys / BioEn

BioEn - Bayesian Inference Of ENsembles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leaked file descriptor in Deer observables class

kain88-de opened this issue · comments

pickle.dump([self.labels, self.moddepth, self.nrestraints, self.exp_tmp,
self.exp_err_tmp, self.sim_tmp], open(self.out_pkl, 'wb'))

This line contains a leak. The call to open returns a file descriptor that is never closed again. This is OK when using only the bioen CLI tool. It will be a problem when using the library from python and analyzing a lot of deer data examples with pkl_out set because each process only is allowed a limited number of open file descriptors. The correct solution would be to use a context manager.

Thanks, the code was improved by introducting a context manager (though CPython should close the file handle automatically, latest when the instance of the Deer class is destructed).

though CPython should close the file handle automatically, latest when the instance of the Deer class is destructed

I thought so too. But some time ago I fixed similar code in the python-mmtf package that showed a lot of leaked file descriptors in tests of MDAnalysis.