1import sqlite3 2 3class CountCursorsConnection(sqlite3.Connection): 4 def __init__(self, *args, **kwargs): 5 sqlite3.Connection.__init__(self, *args, **kwargs) 6 self.numcursors = 0 7 8 def cursor(self, *args, **kwargs): 9 self.numcursors += 1 10 return sqlite3.Connection.cursor(self, *args, **kwargs) 11 12con = sqlite3.connect(":memory:", factory=CountCursorsConnection) 13cur1 = con.cursor() 14cur2 = con.cursor() 15print con.numcursors 16