每当我尝试使用我的 addTask() 和 removeTask() 函数时,我都会等待很长时间,然后出现错误。
以下是功能:
def addTask():
name = raw_input("Enter the name of the task you would like to add: ")
exists = cur.execute("SELECT Name FROM Tasks WHERE Name = '%s';" % name)
if exists:
print("Task already exists.")
else:
cur.execute("INSERT INTO Tasks(Name, Time) VALUES('%s', 0);" % name)
print("'%s' has been added to the task list." % name)
def removeTask():
name = raw_input("Enter name of the task you would like to delete: ")
exists = cur.execute("SELECT Name FROM Tasks WHERE Name = '%s';" % name)
if exists:
cur.execute("DELETE FROM Tasks WHERE Name = '%s';" % name)
print("'%s' has been removed from the task list." % name)
else:
print("Task doesn't exist.")
如果我输入 addTask() 函数中已经存在的名称,它可以正常工作。但是,如果我尝试在 addTask() 函数中添加具有新名称的新任务,则会收到此错误:
Traceback (most recent call last):
File "./timelog3.py", line 137, in <module>
main()
File "./timelog3.py", line 23, in main
addTask()
File "./timelog3.py", line 44, in addTask
cur.execute("INSERT INTO Tasks(Name, Time) VALUES('%s', 0);" % name)
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux- x86_64.egg/MySQLdb/cursors.py", line 202, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')
同样对于删除功能,如果我尝试使用不存在的任务名称,那么它可以正常工作。但是,如果我尝试删除存在的任务,我会得到同样的错误。
真正让我困惑的是几分钟前它工作得很好,我什至没有改变任何东西(或者我不记得我改变了什么)。