Skip to content

Fix file descriptor leak

--HG-- branch : 3.0

In \openpyxl\worksheet\_read_only.py, file descriptors opened using function _get_source() must be closed after use. This is not being done in the two places _get_source() is being used in that module. This MR adds a try..finally block around those two cases and closes the file descriptor.

This fixes issue 1450, where an Excel file remains locked (on Windows) even after the workbook is closed because file descriptors are left open after a partial iteration of worksheets in the file.

I have updated the file descriptor unit test to cover this scenario.

Merge request reports