Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 3398dcb14f6d43bf1619f7c32fe8d888c354e6b2 authored by Ned Deily on 05 December 2017, 08:26:08 UTC
Bump to 3.6.4rc1
Tip revision: 3398dcb
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)
back to top