mdshw5 / pyfaidx

Efficient pythonic random access to fasta subsequences
https://pypi.python.org/pypi/pyfaidx
Other
449 stars 75 forks source link

fix ResourceWarning: unclosed file #202

Closed siebrenf closed 1 year ago

siebrenf commented 1 year ago

I'm seeing cases where a Fasta object is garbage collected without Fasta.faidx.file being closed, resulting in a ResourceWarning: unclosed file <_io.FileIO name='genome.fa' mode='rb' closefd=True>

This PR fixes the warning in the proper way.

I haven't managed to create a simple test case, but this works in my spaghetti code ;)

mdshw5 commented 1 year ago

Thanks @siebrenf. I believe this is the proper method to call, and will confirm before I merge.