[pypy-commit] pypy default: test and fix for _sqlite3.Connection.__del__ (fixes issue 1325)
bdkearns
noreply at buildbot.pypy.org
Tue Mar 5 00:29:37 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r62029:3bf4d0b6f5e8
Date: 2013-03-04 17:49 -0500
http://bitbucket.org/pypy/pypy/changeset/3bf4d0b6f5e8/
Log: test and fix for _sqlite3.Connection.__del__ (fixes issue 1325)
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -343,6 +343,10 @@
if check_same_thread:
self.thread_ident = thread_get_ident()
+ def __del__(self):
+ if self.db:
+ sqlite.sqlite3_close(self.db)
+
def _get_exception(self, error_code = None):
if error_code is None:
error_code = sqlite.sqlite3_errcode(self.db)
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -29,3 +29,20 @@
con = Connection(":memory:")
e = pytest.raises(_sqlite3.ProgrammingError, "con.cursor()")
assert '__init__' in e.value.message
+
+ at pytest.mark.skipif("not hasattr(sys, 'pypy_translation_info')")
+def test_connection_del(tmpdir):
+ """For issue1325."""
+ import gc
+
+ def open_many(cleanup):
+ con = []
+ for i in range(1024):
+ con.append(_sqlite3.connect(str(tmpdir.join('test.db'))))
+ if cleanup:
+ con[i] = None
+ gc.collect(); gc.collect()
+
+ pytest.raises(_sqlite3.OperationalError, open_many, False)
+ gc.collect(); gc.collect()
+ open_many(True)
More information about the pypy-commit
mailing list