pg.InternalError:SSL SYSCALL 错误:检测到 EOF

Ant*_*nin 4 python postgresql asynchronous multiprocessing pgdb

我在 python 中有一个使用多处理和访问数据库的代码。它大部分时间都能正常工作,但有时会产生错误。该错误最初是

File "/usr/lib/python2.7/multiprocessing/pool.py", line 528, in get
    raise self._value
pg.OperationalError: can't rollback
Run Code Online (Sandbox Code Playgroud)

或者

File "/usr/lib/python2.7/multiprocessing/pool.py", line 528, in get
    raise self._value 
pg.InternalError: SSL SYSCALL error: EOF detected
Run Code Online (Sandbox Code Playgroud)

我用来访问数据库的代码是

def getRecords(db,query):
    cur=db.cursor()
    cur.execute(query)
    types=getTypes(cur.description)
    columns=getColumns(cur.description)
    rows=cur.fetchall()
    cur.close()
    try:
        db.commit()
    except:
        db.rollback()
Run Code Online (Sandbox Code Playgroud)

多处理是通过以下方式完成的:

po = multiprocessing.Pool()
for an_element in a_list:
    for an_object in a_list_of_objects:
        results.append(po.apply_async(the_multiprocessed_function, (an_element, an_object)))               
po.close()
po.join()
for r in results:
    some_function_of(r.get())
Run Code Online (Sandbox Code Playgroud)

我想知道我是否在跨进程共享连接,但是对于每个多处理函数,我创建了新连接 (conn = pgdb.connect(...)) 并关闭它 (conn.close())。

然后,我想知道它是否与我提供给我的多处理函数的参数有关,特别是因为它们是我自己定义的类实例,但是为什么这会在 pg 中产生错误?

对不起,如果我的问题不是很清楚,但我不知道在哪里寻找错误。多处理适用于较小的实例和其他表,并且已经过测试。但是当更改查询中的一个表并运行代码以解决更大的问题时,我在某处达到了一些限制。

Ant*_*nin 5

实际上,此错误与多处理无关,而仅与 postgresql/pgrouting 中计算最短路径的函数有关。当没有路径连接网络中的两个点时,该函数将断开与数据库的连接,不作任何解释。有关更多信息,请参见psycopg2.InterfaceError: connection already closed / pgr_astar