[mythtv-commits] mythtv commit: r25200 by wagnerrp

mythtv at cvs.mythtv.org mythtv at cvs.mythtv.org
Tue Jun 29 05:00:51 UTC 2010


      Author: wagnerrp
        Date: 2010-06-29 05:00:51 +0000 (Tue, 29 Jun 2010)
New Revision: 25200
   Changeset: http://svn.mythtv.org/trac/changeset/25200

Modified:

   trunk/mythtv/bindings/python/MythTV/__init__.py
   trunk/mythtv/bindings/python/MythTV/connections.py
   trunk/mythtv/bindings/python/MythTV/database.py
   trunk/mythtv/bindings/python/MythTV/dataheap.py
   trunk/mythtv/bindings/python/MythTV/methodheap.py
   trunk/mythtv/bindings/python/MythTV/mythproto.py
   trunk/mythtv/bindings/python/MythTV/static.py
   trunk/mythtv/bindings/python/MythTV/utility.py

Log:

Rework DBConnection as a connection pool. Each opened cursor now receives its own connection, with a default pool size of 2. When the pool is exhausted, additional connections will be spawned as needed. This allows the database connection to be considered thread safe.

The pool size can be managed with the methods:
  DBConnection.setDefaultSize(size)  # classmethod
  DBConnection.resizePool(size)

The consequence of this change is that all cursors must be manually closed with:
  cursor.close()
Any cursor not closed will result in a leaked connection. This includes cursors lost during error handling. In order to facilitate this, connections and cursors now offer a context manager for the 'with' statement:
  db = MythDB()
  # connection serving as context manager
  with db as cursor:
    cursor.execute(...)
  # cursor serving as context manager
  with db.cursor() as cursor2:
    cursor2.execute(...)
    # nested use is allowed
    with db as cursor3:
      cursor3.execute(...)
In this syntax, the cursor will be automatically closed, and the connection released, as the interpreter exits the context, regardless of exception state.

Refs #8577.





More information about the mythtv-commits mailing list