connection file descriptors created with identical number after process fork on mac

From: Chris Withers <chris(at)simplistix(dot)co(dot)uk>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: connection file descriptors created with identical number after process fork on mac
Date: 2016-08-03 22:48:52
Message-ID: 8d1ddab4-868d-ff1d-f481-1ac95c9c2160@simplistix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-08-03 23:20:00 Re: connection file descriptors created with identical number after process fork on mac
Previous Message Adrian Klaver 2016-08-03 21:47:24 Re: Problem with partitioning