connection file descriptors created with identical number after process fork on mac - Mailing list pgsql-general

From Chris Withers
Subject connection file descriptors created with identical number after process fork on mac
Date
Msg-id 8d1ddab4-868d-ff1d-f481-1ac95c9c2160@simplistix.co.uk
Whole thread Raw
Responses Re: connection file descriptors created with identical number after process fork on mac  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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


pgsql-general by date:

Previous
From: 윤기태
Date:
Subject: Question on table inheritance and privileges
Next
From: Tom Lane
Date:
Subject: Re: connection file descriptors created with identical number after process fork on mac