Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 8ad7d506ca59a5025216b583df3ff069c66bc5a3 authored by Ɓukasz Langa on 20 July 2020, 17:47:09 UTC
Python 3.9.0b5
Tip revision: 8ad7d50
countcursors.py
import sqlite3

class CountCursorsConnection(sqlite3.Connection):
    def __init__(self, *args, **kwargs):
        sqlite3.Connection.__init__(self, *args, **kwargs)
        self.numcursors = 0

    def cursor(self, *args, **kwargs):
        self.numcursors += 1
        return sqlite3.Connection.cursor(self, *args, **kwargs)

con = sqlite3.connect(":memory:", factory=CountCursorsConnection)
cur1 = con.cursor()
cur2 = con.cursor()
print(con.numcursors)

con.close()
back to top