为了访问数据库并避免同时进行两次提交,我尝试使用BoundedSemaphore
(see here),如下所示:
from threading import BoundedSemaphore
...
commit_sema = BoundedSemaphore(value=1)
class Sqlite(object):
...
def commit():
commit_sema.acquire()
self.conn.commit() # self.conn is the Connection object
commit_sema.release()
但是,尽管我确保使用了Sqlite
类的同一个实例,但我发现在第一个调用完成之前,第二个commit()
调用已经发出。在
我的印象是第二个调用应该被阻止,直到第一个调用release()
来增加Semaphore
计数器。但事实并非如此。在
那么我觉得这有什么不对?如何正确操作?在
目前没有回答
相关问题 更多 >
编程相关推荐