File closing do not work on Windows in Python 3.11.8
The Excell file seems to not close on Windows in Python 3.11.8 (it works correctly in Python 3.11.7). The example to reproduce:
import os
import openpyxl
import pandas as pd
pd.DataFrame({"A": [1, 2], "B": [3, 4]}).to_excel("test.xlsx")
workbook = openpyxl.load_workbook("test.xlsx", data_only=True)
os.remove("test.xlsx")
Throws error:
Traceback (most recent call last):
File "C:\Users\anago\Desktop\orange3\example.py", line 8, in <module>
os.remove("test.xlsx")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'test.xlsx'
If I understand correctly when Workbook is not read_only and write_only it closes right after reading (in load_workboo), but it seems it is not working correctly in Python 3.11.8. It works in Python 3.11.7 and all older versions. I tried to debug a bit but couldn't come to the end yet. Do you have any idea about this issue? It seems that something changed in Python 3.11.8.
Edited by Primož Godec