conn.rollback()
cur.close()
conn.close()
sys.exit(2)
try:
    cur.execute('update X set total = 80 where id = 1')
except MySQLdb.Error as e:
    print(e[0], e[1])
conn.rollback()
cur.close()
conn.close()
sys.exit(2)
conn.commit()
cur.close()
conn.close()
Python-mysql: when to explicitly rollback a transaction