def wrapper(*args, **kwargs): conn = None c = None try: # The calling function might want to supply the connections themselves and close them later. if 'connection' not in kwargs: conn = get_connection() kwargs['connection'] = conn if 'cursor' not in kwargs: c = kwargs['connection'].cursor() kwargs['cursor'] = c return function(*args, **kwargs) except Exception as e: DEFAULT_LOGGER.error("Error running DB query: " + str(e)) finally: if c is not None: c.close() if conn is not None: conn.close()
def get_graph(): try: g = RoadGraph.load_graph("graph.pickle") return g except: DEFAULT_LOGGER.error("Could not load graph")