【问题标题】:Why does windows give an sqlite3.OperationalError and linux does not?为什么 windows 会给出 sqlite3.OperationalError 而 linux 不会?
【发布时间】:2009-03-25 14:04:53
【问题描述】:

问题

我有一个使用 storm 0.14 的程序,它在 Windows 上给了我这个错误:

sqlite3.OperationError:数据库表被锁定

问题是,在 linux 下它可以正常工作。

我的印象是它只有在完成一定数量的更改后才会发生,就像在某些代码中发生的那样,它会复制很多对象。

在 Windows 上打开调试模式会给我这个:

83 执行:'更新常规订单产品设置折扣=?在哪里常规order_product.order_id =? AND regularorder_product.product_id = ?', (Decimal("25.00"), 788, 274) 84 完成 85 执行:'更新重复订单集 nextDate=? WHERE repeat_orders.id = ?', (datetime.date(2009, 3, 31), 189) 86 错误:数据库表被锁定

在 Linux 上:

83 执行:'更新常规订单产品设置折扣=?在哪里常规order_product.order_id =? AND regularorder_product.product_id = ?', (Decimal("25.00"), 789, 274) 84 完成 85 执行:'更新重复订单集 nextDate=? WHERE repeat_orders.id = ?', (datetime.date(2009, 3, 31), 189) 86 完成

系统信息

Windows

  • Windows XP SP 3
  • Python 2.5.4
  • NTFS 分区

Linux

  • Ubuntu 8.10
  • Python 2.5.2
  • ext3 分区

一些代码

def createRegularOrderCopy(self):
    newOrder = RegularOrder()
    newOrder.date = self.nextDate
    # the exception is thrown on the next line,
    # while calling self.products.__iter__
    # this happens when this function is invoked the second time
    for product in self.products:
        newOrder.customer = self.customer
        newOrder.products.add(product)
        return newOrder

orders = getRepeatedOrders(date)
week = timedelta(days=7)

for order in orders:
    newOrder = order.createRegularOrderCopy()
    store.add(newOrder)
    order.nextDate = date + week

问题

sqlite3/python 在 windows 和 linux 之间有什么不同吗?这个错误可能是什么原因造成的,我该如何解决?

另一个观察

在发生错误的地方添加COMMIT时,会抛出此错误:sqlite3.OperationalError: cannot commit transaction - SQL statements in progress

答案的答案

我没有使用多个线程/进程,因此并发应该不是问题,而且我只有一个 Store 对象。

【问题讨论】:

    标签: python windows linux sqlite


    【解决方案1】:

    “数据库表已锁定”错误通常是 SQLite 中的一般/默认错误,因此缩小问题范围并不明显。

    您是否能够执行任何 SQL 查询?我将从那里开始,并让一些基本的 SELECT 语句正常工作。这可能只是权限问题。

    【讨论】:

    • 是的,40 条语句才能完美运行。 (最后一个包含在问题中。)
    【解决方案2】:

    很难说没有关于数据库访问结构的更多信息(使用 Storm 有点模糊)。

    我会先阅读这些文件;它们包含非常相关的信息:

    1. https://storm.canonical.com/Manual#SQLite%20and%20threads

    2. http://sqlite.org/lockingv3.html

    【讨论】:

      【解决方案3】:

      您是否正在运行任何类型的防病毒扫描程序?防病毒扫描程序会在文件更新后经常锁定文件,以便他们可以在不更改文件的情况下对其进行检查。这可以解释为什么在进行大量更改后会出现此错误;防病毒扫描程序有更多新数据要扫描。

      如果您正在运行防病毒扫描程序,请尝试将其关闭,看看是否可以重现此问题。

      【讨论】:

        【解决方案4】:

        在我看来,storm 好像坏了,虽然我的第一个猜测是按照 Brian 的建议进行病毒扫描。

        您是否尝试过使用sqlite3_busy_timeout() 将超时设置得非常高?这可能会导致SQLite3 等待足够长的时间让锁持有者(无论是谁)释放锁。

        【讨论】:

        • 5 秒够高吗?我使用的是storm的“python”版本,所以windows和linux之间应该没有区别。我目前正在调查是否安装了不同版本的 sqlite。
        【解决方案5】:

        我现在通过用最新版本替换 sqlite3-dll 解决了这个问题。我仍然不确定这是否是 sqlite 的 windows 代码中的错误,或者 python 在 windows 上安装的版本是否比在 linux 上的旧版本。

        感谢您的帮助。

        【讨论】:

        • 你可以通过'import sqlite3', 'print sqlite3.sqlite_version'查看sqlite版本。如果你把原来的sqlite3.dll放回去,你就可以比较了。
        • Linux:3.5.9,Windows:3.4.4,差别很大。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-10-12
        • 1970-01-01
        • 1970-01-01
        • 2014-06-22
        • 2023-02-04
        • 2013-02-18
        相关资源
        最近更新 更多