Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g803I-0003FL-NW for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 09:36:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g803H-00035d-EW for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 09:36:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7zzz-0000y7-8l for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 09:32:47 +0000 Received: from mail.dndg.it ([178.32.136.2]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7zzs-0000Ju-0j for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 09:32:46 +0000 Received: from [10.94.33.108] (93-50-194-114.ip153.fastwebnet.it [93.50.194.114]) by mail.dndg.it (Postfix) with ESMTPSA id 3B88DA02E0 for ; Thu, 4 Oct 2018 09:37:59 +0000 (UTC) Subject: Re: Integration of Psycopg with XTA To: psycopg@lists.postgresql.org References: <2001056273.7945904.1537909025251.ref@mail.yahoo.com> <2001056273.7945904.1537909025251@mail.yahoo.com> <1171000727.19526618.1537994198139@mail.yahoo.com> <2038369023.20583382.1538078255866@mail.yahoo.com> <106450562.4254785.1538510870700@mail.yahoo.com> <4d647279-19ae-75ea-83a7-b74b647c79bd@dndg.it> <69747703.5400338.1538599809000@mail.yahoo.com> From: Federico Di Gregorio Organization: DNDG srl Message-ID: Date: Thu, 4 Oct 2018 11:32:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <69747703.5400338.1538599809000@mail.yahoo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SURBL_BLOCKED, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/03/2018 10:50 PM, Christian Ferrari wrote: [snip] > > I guess the capsule is meant to be consumed by the other API and using a > > method makes is explicit that a new object is instantiated every time. I > > really don't care about this, let's do whatever is more Pythonic. > > Dear Daniele & Federico, > I'm not a "pythonist" at all, I can't provide suggestions about "Python > style". > In oo context, typically I expect to call a method when I need to > retrieve something, that's why I proposed a method instead of a property. > Anyway, my obscure question was related to garbage collection: who is in > charge of destroying the capsule and how it must be destroyed? > Looking at this example: > > pgconn = xx._get_pgconn() > do_something(pgconn) > pgconn = yy._get_pgconn() > > will the first capsule be automatically destroyed by the Python runtime > when pgconn is assigned to another one (yy....)? Or some explicit > statement must be executed? > If everything is automatically managed by the Python runtime, I will be > very happy. If "do_something()" must release the capsule to avoid memory > leaks, I have to implement it. The capsule is a standard reference-counted Python object. If the API just use the pointer inside it and does not keep a reference to the Python object itself, it will be free'd by the gc when the reference count goes to 0. In your example, the first capsule is garbage collected when you assign the second one to the same variable "pgconn". @Daniele, I see that a capsule has an implicit state, "invalid" if the pointer inside it is null. Does it makes sense to reuse the same capsule and keep a reference to it to be able to invalidate it when the connection is closed? federico -- Federico Di Gregorio federico.digregorio@dndg.it DNDG srl http://dndg.it The only thing I see is if you are pumping so much data into the database all the time when do you expect to look at it? -- Charlie Clark