psycopg 및 다중 처리를 사용하여 수백만 개의 행을 삽입하고 업데이트하려고합니다. http://initd.org/psycopg/docs/usage.html#thread-and-process-safety에있는 설명서를 보면 각 자식은 DB에 자체 연결되어 있습니다.다중 처리 + psycopg2 좀비 하위
그러나 실행 중에는 다른 자식이 좀비가되는 동안 한 명의 자식 만 실행됩니다. 자체 스크립트는
import os
import psycopg2
from multiprocessing import Process
def _target(args):
# Each forked process will have its own connection
# http://initd.org/psycopg/docs/usage.html#thread-and-process-safety
conn = get_db_connection()
# Stuff seems to execute till this point in all the children
print os.getpid(), os.getppid()
# Do some updates here. After this only one child is active and running
# Others become Zombies after a while.
if __name__ == '__main__':
args = "Foo"
for i in xrange(3):
p = Process(target=_target, args=(args,))
p.start()
테이블이 pg_locks
에 엿하여 신고 된 잠금이있는 경우 또한 확인하지만이 아니 경우처럼 보이는, 아주 간단하고 여기에 동일한의 손질 버전입니다. 나는 명백한 것을 놓치고 있는가?
무엇을 할 get_db_connection합니까? 새 연결을 만들거나 공유 연결을 반환합니까? 사용자가 지정한 문서에 따르면 새로운 연결을 만들어야합니다. –
Philip, 아니요. 공유 연결을 사용하지 않습니다. 분기 된 각 자식에 대해 새로운 연결 및 커서 집합이 만들어집니다. (create_db_connection()) – sudharsh