def teardown_request(self, exception): ctx = _ctx_stack.top if hasattr(ctx, "mysql_db"): ctx.mysql_db.close()