InternalError:当前事务中止,命令被忽略,直到事务块结束 [英] InternalError: current transaction is aborted, commands ignored until end of transaction block

查看:165
本文介绍了InternalError:当前事务中止,命令被忽略,直到事务块结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用多处理库的子进程中进行数据库调用时,出现此错误.

I'm getting this error when doing database calls in a sub process using multiprocessing library.

访问: Pastie

InternalError:当前事务中止,命令被忽略,直到 交易结束区块

InternalError: current transaction is aborted, commands ignored until end of transaction block

这是使用web.py中的psycopg2驱动程序的Postgre数据库.

this is to a Postgre Database, using psycopg2 driver in web.py.

但是,如果我使用threading.Thread而不是multiprocessing.Process,则不会出现此错误.
知道如何解决这个问题吗?

However if I use threading.Thread instead of multiprocessing.Process I don't get this error.
Any idea how to fix this?

推荐答案

(在UNIX系统上)多处理通过分叉当前进程而起作用.如果您有一个现有的数据库连接,这将使两个进程(当前进程和新进程)具有相同的数据库连接.试图同时使用它是不好的.而是在子进程中创建一个新的数据库连接.

multiprocessing works (on UNIX systems) by forking the current process. If you have an existing database connection, this will leave the two processes (the current one and the new one) with the same database connection. Trying to use it from both is bad. Create a new database connection in the child process instead.

这篇关于InternalError:当前事务中止,命令被忽略,直到事务块结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆