openpyxl leaks file handle in py py implementation
Created originally on Bitbucket by simoscofield (C. W.)
Here is the code to reproduce:
#!python
import openpyxl
import psutil
proc = psutil.Process()
open_files_l1 = proc.open_files()
print("number of open file handles: %s" % len(open_files_l1))
b = openpyxl.load_workbook(
filename="test.xlsx", data_only=True, read_only=True)
b.close()
open_files_l2 = proc.open_files()
print("number of open file handles: %s" % len(open_files_l2))
print(open_files_l2)
assert len(open_files_l1) == len(open_files_l2)
And here is the result
#!bash
$ python test.py
number of open file handles: 0
number of open file handles: 2
[popenfile(path='/Users//github/pyexcel-xlsx/test.xlsx', fd=5), popenfile(path='/Users//github/pyexcel-xlsx/test.xlsx', fd=6)]
Traceback (most recent call last):
File "test.py", line 14, in <module>
assert len(open_files_l1) == len(open_files_l2)
AssertionError
$ python
Python 2.7.13 (1aa2d8e03cdf, Mar 31 2017, 10:20:53)
[PyPy 5.7.1 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Attachments: test.xlsx