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

Поиск
Список
Период
Сортировка
От Chris Withers
Тема connection file descriptors created with identical number after process fork on mac
Дата
Msg-id 8d1ddab4-868d-ff1d-f481-1ac95c9c2160@simplistix.co.uk
обсуждение исходный текст
Ответы Re: connection file descriptors created with identical number after process fork on mac  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: 윤기태
Дата:
Сообщение: Question on table inheritance and privileges
Следующее
От: Tom Lane
Дата:
Сообщение: Re: connection file descriptors created with identical number after process fork on mac