[pypy-issue] Issue #2006: OperationalError when there are a lot of sqlite3 databases to close in GC (pypy/pypy)
David MacIver
issues-reply at bitbucket.org
Mon Mar 23 19:03:15 CET 2015
New issue 2006: OperationalError when there are a lot of sqlite3 databases to close in GC
https://bitbucket.org/pypy/pypy/issue/2006/operationalerror-when-there-are-a-lot-of
David MacIver:
In advance: I know you're going to tell me to please close my databases and I will do so. :-) I thought you'd probably want to know about this bug anyway.
The following code when run produces a whole bunch of messages of the form
Exception OperationalError: OperationalError(u'unable to close due to unfinalised statements',) in method __del__ of <__main__.SQLiteBackend object at 0x00000000024ee2a8> ignored
```
#!python
import sqlite3
class SQLiteBackend(object):
def __init__(self):
self.connection = sqlite3.connect(":memory:")
def close(self):
self.connection.close()
def __del__(self):
self.close()
def create_db_if_needed(self):
conn = self.connection
cursor = conn.cursor()
try:
cursor.execute("""
create table if not exists hypothesis_data_mapping(
value text
)
""")
finally:
cursor.close()
conn.commit()
if __name__ == '__main__':
dbs = []
for i in xrange(1000):
SQLiteBackend().create_db_if_needed()
```
Reducing the number of databases to ~100 it seems to no longer produce these errors.
More information about the pypy-issue
mailing list