Re: Integration of Psycopg with XTA

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: psycopg(at)lists(dot)postgresql(dot)org
Subject: Re: Integration of Psycopg with XTA
Date: 2018-10-04 09:32:35
Message-ID: f1ef39bf-3bb2-1fde-0d31-92fea9335a83@dndg.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

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(dot)digregorio(at)dndg(dot)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

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2018-10-04 10:13:43 Re: Integration of Psycopg with XTA
Previous Message Akshay Joshi 2018-10-04 05:35:19 Copy command hangs in poll() function