MySQL Forums
Forum List  »  Connector/Python

unclosed files in mysql/connector/optionfiles.py
Posted by: 7 reeds
Date: July 13, 2020 03:35PM

Hi,

I don't know if I am reporting a bug or my misunderstanding. I am running Python 3.8.x from a virtualenv on a Linux Mint 19.x system. I have the latest pip install of MySQL Connector for Python.

I was running a test suit on an app I am building. I had just rearranged where I was doing the DB connections -- this app responds to async requests and I don't know enough about MySQL connections in this environment.

I received a message about a file being opn in the MySQL Connector venv/lib/python3.8/site-packages/mysql/connector/optionfiles.py in the "read()" method. That method has the line:

for line in codecs.open(filename, encoding='utf-8'):

The file(s) are obviously read but they do not appear to be explicitly closed.

I modified that line to:

in_file = codecs.open(filename, encoding='utf-8')
for line in in_file:

and added

in_file.close()

immediately after the loop. That mostly seemed to do the trick for me but maybe there are unintended consequences I can't see?

If this is a reasonable modification what is the recommended way to send a patch?


Lastly, after making that change and in the same file in the "read_option_files()" method there is a line:

except KeyError:
if group is 'connector_python':

I had a warning that the "is" should be "==" for the constant. This might be a python version thing, don't know.

Cheers

Options: ReplyQuote


Subject
Written By
Posted
unclosed files in mysql/connector/optionfiles.py
July 13, 2020 03:35PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.