class LocalManager:
    """Requests a connection from a Pycassa Pool when needed, and releases it at the end of the object's life"""

def __init__(self, pool):
    """Class constructor"""
assert isinstance(pool, Pool)
self._pool = pool
self._conn = None

def get(self):
    """Grabs a connection from the pool if not already done, and returns it"""
if self._conn is None:
    self._conn = self._pool.get()
return self._conn

def __getattr__(self, key):
    """It's cooler to write "c.conn" than "c.get()" in the code, isn't it?"""
if key == 'conn':
    return self.get()
else:
    return self.__dict__[key]

def __del__(self):
    """Releases the connection, if needed"""
if not self._conn is None:
    self._conn.return_to_pool()
Как подключиться к Cassandra внутри приложения Pylons?