#上下文管理
class dbcnn(object):
def __init__(self, cnxp):
self.cnn = cnxp.get_connection()
def __enter__(self):
return self.cnn
def __exit__(self, *exc_info):
self.cnn.commit()
self.cnn.close()
logging.warning(exc_info)
@contextmanager
def dbtest(cnxpool):
try:
cnn = cnxpool.get_connection()
yield cnn
except Exception as e:
logging.warning(traceback.format_exc())
pass