[英]InternalError: current transaction is aborted, commands ignored until end of transaction block
I'm getting this error when doing database calls in a sub process using multiprocessing library. 使用多处理库在子进程中进行数据库调用时出现此错误。
InternalError: current transaction is aborted, commands ignored until end of transaction block
InternalError:当前事务中止,命令被忽略,直到事务块结束
this is to a Postgre Database, using psycopg2
driver in web.py
. 这是使用
web.py
psycopg2
驱动程序的Postgre数据库。
However if I use threading.Thread
instead of multiprocessing.Process
I don't get this error. 但是,如果我使用
threading.Thread
而不是multiprocessing.Process
,则不会出现此错误。
Any idea how to fix this? 任何想法如何解决这个问题?
multiprocessing works (on UNIX systems) by forking the current process. 多处理通过分叉当前进程来工作(在UNIX系统上)。 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.
而是在子进程中创建一个新的数据库连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.