0.24 Python bindings/Advanced
This page is for advanced objects, not included in the normal import of the bindings, and for most purposes are not needed.
Connection Classes
DBConnection
This connection takes a single input, dbconn, which is a dictionary containing:
- DBUserName
- DBHostName
- DBPassword
- DBName
- DBPort
This class provides automatic connection pooling. All database access is performed through the cursor interface, and in order to maintain thread safety, a single connection will only be shared among cursors of the same thread. If more threads attempt to access the database simultaneously than there are connections, a new single use connection will be opened for that specific cursor.
'release' and 'acquire' methods are available to manage the use of connections in the pool, and to automatically spawn new ones if needed. '__enter__' and '__exit__' exist for use as a context manager, and will return a new cursor to use. Each thread is given its own stack in the context manager, so multiple nested cursors are allowed.
The pool size is adjustable. The default pool size for new connection objects can be set with the 'setDefaultSize' classmethod, and an existing connection can be resized with the 'resizePool' method.
BEConnection
This connection takes the following inputs:
- backend - must be an IP address
- port
- localname=None - if not set, will pull it from socket.gethostname()
- opts=None - a BEConnOpts dictionary providing the capabilities of the connection
- deadline=10 - a float specifying how long a query may wait for a response