[mythtv-commits] Ticket #8577: Python Bindings Reorganization

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


#8577: Python Bindings Reorganization
-------------------------------+--------------------------------------------
 Reporter:  wagnerrp           |       Owner:  wagnerrp  
     Type:  task               |      Status:  accepted  
 Priority:  minor              |   Milestone:  0.24      
Component:  Bindings - Python  |     Version:  Trunk Head
 Severity:  medium             |     Mlocked:  0         
-------------------------------+--------------------------------------------

Comment(by wagnerrp):

 (In [25200]) 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.

-- 
Ticket URL: <http://svn.mythtv.org/trac/ticket/8577#comment:6>
MythTV <http://www.mythtv.org/>
MythTV


More information about the mythtv-commits mailing list