Skip to content

Commit 23558d6

Browse files
committed
Fixed load data infile file handle bug.
-The file handle for that reads the local file for a load data local infile command is never closed. This can cause issues if you are running hundreds of load data commands as you run out of python IO handles. -Fixed the bug by adding a finally clause to always close the files.
1 parent 2ce54ea commit 23558d6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/mysql/connector/connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ def _handle_load_data_infile(self, filename):
399399
"""Handle a LOAD DATA INFILE LOCAL request"""
400400
try:
401401
data_file = open(filename, 'rb')
402+
return self._handle_ok(self._send_data(data_file,
403+
send_empty_packet=True))
402404
except IOError:
403405
# Send a empty packet to cancel the operation
404406
try:
@@ -408,9 +410,13 @@ def _handle_load_data_infile(self, filename):
408410
"MySQL Connection not available.")
409411
raise errors.InterfaceError(
410412
"File '{0}' could not be read".format(filename))
413+
finally:
414+
try:
415+
data_file.close()
416+
except IOError, NameError:
417+
# don't worry if the file was never opened
418+
pass
411419

412-
return self._handle_ok(self._send_data(data_file,
413-
send_empty_packet=True))
414420

415421
def _handle_result(self, packet):
416422
"""Handle a MySQL Result

0 commit comments

Comments
 (0)