Skip to content

Python reports unclosed files #34

@osvenskan

Description

@osvenskan

While running our project with -W default per the recommendation of Python 3.9, we saw a few warnings about unclosed files which we traced to pyxlsb. Here's a simple demo using 2010_InsPubActs.xlsb which is an XLSB that I found online but I think any XLSB would work.

$ python 
Python 3.8.8 (v3.8.8:024d8058b0, Feb 19 2021, 08:48:17)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyxlsb
>>> pyxlsb.__version__
'1.0.8'
>>> workbook = pyxlsb.open_workbook('2010_InsPubActs.xlsb')
>>> [workbook.get_sheet(sheet_name) for sheet_name in workbook.sheets]
[<pyxlsb.worksheet.Worksheet object at 0x7fd53802be80>]
>>> workbook.close()
>>> ^D
sys:1: ResourceWarning: unclosed file <_io.BufferedRandom name=6>
ResourceWarning: Enable tracemalloc to get the object allocation traceback

I noticed that there's one or two TemporaryFile instances being passed to the call to Worksheet on line 84; maybe they're not getting closed?

Thanks for pyxlsb!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions