Re: Integration of Psycopg with XTA - Mailing list psycopg

From Christian Ferrari
Subject Re: Integration of Psycopg with XTA
Date
Msg-id 69747703.5400338.1538599809000@mail.yahoo.com
Whole thread Raw
In response to Re: Integration of Psycopg with XTA  (Federico Di Gregorio <fog@dndg.it>)
Responses Re: Integration of Psycopg with XTA  (Federico Di Gregorio <fog@dndg.it>)
List psycopg
On 10/03/2018 02:52 PM, Daniele Varrazzo wrote:
> On Wed, Oct 3, 2018 at 1:44 PM Federico Di Gregorio<fog@dndg.it>  wrote:
>> On 10/03/2018 02:37 PM, Daniele Varrazzo wrote:
>>> On Wed, Oct 3, 2018 at 1:28 PM Federico Di Gregorio<fog@dndg.it>  wrote:
>>>
>>>>> This is interesting because PyCapsule is for sure a "clean" way to pass
>>>>> the pointer from Psycopg to XTA.
>>> Fog, maybe it's worth adding the capsules for PGconn and PGresult to
>>> the objects interface and document them? Can do that for psycopg 2.8.
>> If it works I'd add it (and document it as an "internal" extension point
>> used by other C-level modules) for 2.8, yes.
>>
>> By PGresult you mean adding it on the cursor, or the connection?
> Yes, i'd say a _pgconn attribute or _get_pgconn() method on the
> connection, a _pgresult thing on the cursor.
>
> By the way a read-only attribute as per your implementation seems
> appropriate to me. Christian, why do you think a function would be
> better?

> 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.

I will be very happy to test a "release candidate" version of the feature and link next LIXA/XTA release with psycopg 2.8.

K.R.
Ch.F.



psycopg by date:

Previous
From: Federico Di Gregorio
Date:
Subject: Re: Integration of Psycopg with XTA
Next
From: Akshay Joshi
Date:
Subject: Copy command hangs in poll() function