Remove BaseCursor.__del__

Fixes #22 (Uncollectable cursor on Python 3.3)
This commit is contained in:
INADA Naoki
2015-02-25 03:53:21 +09:00
parent cac52c9541
commit a5716c33e4
2 changed files with 8 additions and 20 deletions

View File

@ -17,7 +17,6 @@ import re
def defaulterrorhandler(connection, cursor, errorclass, errorvalue): def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
""" """
If cursor is not None, (errorclass, errorvalue) is appended to If cursor is not None, (errorclass, errorvalue) is appended to
cursor.messages; otherwise it is appended to cursor.messages; otherwise it is appended to
connection.messages. Then errorclass is raised with errorvalue as connection.messages. Then errorclass is raised with errorvalue as
@ -25,7 +24,6 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
You can override this with your own error handler by assigning it You can override this with your own error handler by assigning it
to the instance. to the instance.
""" """
error = errorclass, errorvalue error = errorclass, errorvalue
if cursor: if cursor:

View File

@ -44,7 +44,6 @@ from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \
class BaseCursor(object): class BaseCursor(object):
"""A base for Cursor classes. Useful attributes: """A base for Cursor classes. Useful attributes:
description description
@ -59,7 +58,6 @@ class BaseCursor(object):
arraysize arraysize
default number of rows fetchmany() will fetch default number of rows fetchmany() will fetch
""" """
from _mysql_exceptions import MySQLError, Warning, Error, InterfaceError, \ from _mysql_exceptions import MySQLError, Warning, Error, InterfaceError, \
@ -85,17 +83,15 @@ class BaseCursor(object):
self._info = None self._info = None
self.rownumber = None self.rownumber = None
def __del__(self):
self.close()
self.errorhandler = None
self._result = None
def close(self): def close(self):
"""Close the cursor. No further queries will be possible.""" """Close the cursor. No further queries will be possible."""
if self.connection is None or self.connection() is None: if self.connection is None or self.connection() is None:
return return
while self.nextset(): pass while self.nextset():
pass
self.connection = None self.connection = None
self.errorhandler = None
self._result = None
def _check_executed(self): def _check_executed(self):
if not self._executed: if not self._executed:
@ -124,7 +120,7 @@ class BaseCursor(object):
if self._executed: if self._executed:
self.fetchall() self.fetchall()
del self.messages[:] del self.messages[:]
db = self._get_db() db = self._get_db()
nr = db.next_result() nr = db.next_result()
if nr == -1: if nr == -1:
@ -135,7 +131,7 @@ class BaseCursor(object):
return 1 return 1
def _post_get_result(self): pass def _post_get_result(self): pass
def _do_get_result(self): def _do_get_result(self):
db = self._get_db() db = self._get_db()
self._result = self._get_result() self._result = self._get_result()
@ -162,7 +158,6 @@ class BaseCursor(object):
return con return con
def execute(self, query, args=None): def execute(self, query, args=None):
"""Execute a query. """Execute a query.
query -- string, query to execute on server query -- string, query to execute on server
@ -173,9 +168,9 @@ class BaseCursor(object):
%(key)s must be used as the placeholder. %(key)s must be used as the placeholder.
Returns long integer rows affected, if any Returns long integer rows affected, if any
""" """
del self.messages[:] while self.nextset():
pass
db = self._get_db() db = self._get_db()
# NOTE: # NOTE:
@ -206,23 +201,19 @@ class BaseCursor(object):
except TypeError as m: except TypeError as m:
if m.args[0] in ("not enough arguments for format string", if m.args[0] in ("not enough arguments for format string",
"not all arguments converted"): "not all arguments converted"):
self.messages.append((ProgrammingError, m.args[0]))
self.errorhandler(self, ProgrammingError, m.args[0]) self.errorhandler(self, ProgrammingError, m.args[0])
else: else:
self.messages.append((TypeError, m))
self.errorhandler(self, TypeError, m) self.errorhandler(self, TypeError, m)
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
raise raise
except: except:
exc, value = sys.exc_info()[:2] exc, value = sys.exc_info()[:2]
self.messages.append((exc, value))
self.errorhandler(self, exc, value) self.errorhandler(self, exc, value)
self._executed = query self._executed = query
if not self._defer_warnings: self._warning_check() if not self._defer_warnings: self._warning_check()
return r return r
def executemany(self, query, args): def executemany(self, query, args):
"""Execute a multi-row query. """Execute a multi-row query.
query -- string, query to execute on server query -- string, query to execute on server
@ -237,7 +228,6 @@ class BaseCursor(object):
This method improves performance on multiple-row INSERT and This method improves performance on multiple-row INSERT and
REPLACE. Otherwise it is equivalent to looping over args with REPLACE. Otherwise it is equivalent to looping over args with
execute(). execute().
""" """
del self.messages[:] del self.messages[:]
db = self._get_db() db = self._get_db()