Hi All,
I'm writing some multi-process code in Python and trying to make sure I
open a new connection for each process. Here's the really cut down code:
"""
import os, time
import psycopg2
from multiprocessing import Pool
def init():
conn = psycopg2.connect("dbname=...host=localhost")
print os.getpid(), ' child fd:', conn.fileno()
if __name__=='__main__':
pool = Pool(initializer=init)
time.sleep(30)
"""
What's really surpising to me is the output on a mac:
$ python psycopg2_multiprocess.py
44276 child fd: 13
44277 child fd: 13
44278 child fd: 13
44279 child fd: 13
The getpid() output indicates that the connec() call is being made
inside a different process each time, yet the connection appears to
still be using the same fd.
conn.file() is basically (long int)PQsocket(self->pgconn);:
https://github.com/psycopg/psycopg2/blob/master/psycopg/connection_type.c#L898
Is there something I'm missing about file descriptors on Macs or is
something bad happening here?
Chris
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general