Commit 293ddd28 authored by Alex Gaynor's avatar Alex Gaynor Committed by Denis Bilenko

Simplify the db pool example (From PR #239)

parent 846723c9
......@@ -89,30 +89,8 @@ class DatabaseConnectionPool(object):
@contextlib.contextmanager
def cursor(self, *args, **kwargs):
isolation_level = kwargs.pop('isolation_level', None)
conn = self.get()
try:
if isolation_level is not None:
if conn.isolation_level == isolation_level:
isolation_level = None
else:
conn.set_isolation_level(isolation_level)
with self.connection(isolation_level) as conn:
yield conn.cursor(*args, **kwargs)
except:
if conn.closed:
conn = None
self.closeall()
else:
conn = self._rollback(conn)
raise
else:
if conn.closed:
raise OperationalError("Cannot commit because connection was closed: %r" % (conn, ))
conn.commit()
finally:
if conn is not None and not conn.closed:
if isolation_level is not None:
conn.set_isolation_level(isolation_level)
self.put(conn)
def _rollback(self, conn):
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment