“有时”使用Peewee ORM在PostgreSQL上获取InterfaceError

时间:2014-04-06 12:26:57

标签: python postgresql orm interface peewee

我正在使用Python Flask framework构建一个网站,使用PostgreSQL 9.3构建Peewee ORM。到目前为止事情进展顺利,但我现在遇到了一些麻烦。我有时会得InterfaceError: connection already closed。我得到它的代码如下:

pendingOrders_q = CustomerOrder\
    .select()\
    .where(CustomerOrder.status == CustomerOrder.STATUS_PENDING)\
    .where(CustomerOrder.expiration < datetime.utcnow())

if len(list(pendingOrders_q)) > 0:
    # do some stuff here..

我知道我计算结果数量的方式非常讨厌,但我不知道其他任何方法。此外,这通常有效,但有时它会给出以下错误。我不明白为什么它通常工作正常,但有时会出现此错误。有谁知道这里发生了什么?

  File "/home/kramer65/xs/app/order_management.py", line 210, in checkExpiration
    if len(list(pendingOrders_q)) > 0:
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1988, in __iter__
    return iter(self.execute())
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1981, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1698, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 251, in execute_sql
    self.commit()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2104, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 242, in execute_sql
    cursor = self.get_cursor()
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 229, in get_cursor
    return self.get_conn().cursor(name=name)
InterfaceError: connection already closed

[编辑] 我现在突然也得到了该行的以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/apscheduler/scheduler.py", line 512, in _run_job
    retval = job.func(*job.args, **job.kwargs)
  File "/home/kramer65/xs/app/order_management.py", line 207, in checkForDetails
    for order in paidInOrders_q:
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1411, in next
    obj = self.iterate()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1392, in iterate
    row = self.cursor.fetchone()
InterfaceError: cursor already closed

0 个答案:

没有答案