Peewee保存点不存在。

5

我正在使用peewee来连接一个MySQL数据库。我有一系列的条目需要插入到数据库中,如果它们已经存在,则需要更新。我使用create_or_get函数来实现这个功能。我还使用了线程来加快处理速度;代码如下:

# pool is just a map wrapper around standard threading module
pool  = utils.ThreadPool()
    for page in xrange(0, pages):
        pool.add_task(self.update_page, page)
pool.wait_completion()

def update_page(self, num):
    for entry in self.get_entries_from_page(num):
        self.push_entry(entry)

def push_entry(self, entry):
    with _db.execution_context():
        result, new = EntryModel.create_or_get(**entry) # << error  here
        if not new :
            if entry['date'] > result.date:
                result.hits += 1
                result.date = track['date']
                result.save()

数据库初始化:

_db.initialize(playhouse.pool.PooledMySQLDatabase(n, user = u, passwd = w, host = h, port = p))

一切都运行得很顺利,但突然间我开始在提到的这一行代码上收到许多错误信息:

(1305, 'SAVEPOINT s449cd5a8d165440aaf47b205e2932362 不存在')

保存点编号每次都会更改,导致数据无法写入数据库。重新创建数据库没有帮助。什么可能会导致这个错误呢?

1个回答

0

尝试在创建数据库连接时移除autocommit=True。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接