Re: Connection pooling and with statement

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Frank Broniewski <brfr(at)metrico(dot)lu>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Connection pooling and with statement
Date: 2013-08-27 07:50:15
Message-ID: CA+mi_8bTK82k8J68F6_dfvQQ71vW2Frm0vEOEtx4WsqCwCeCFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Tue, Aug 27, 2013 at 8:13 AM, Frank Broniewski <brfr(at)metrico(dot)lu> wrote:
> Am 2013-08-23 12:03, schrieb Frank Broniewski:
>
>> Another question that occured to me is how I use the with statement with
>> the pool class:
>>
>> I can do:
>> with pool.getconn() as conn:
>> with conn.cursor() as cursor:
>> # do stuff
>>
>> Where do I need to call pool.putconn(conn)? How does the with statement
>> affect the connection? Is the with statement suitable for connection
>> pooling at all?
>
>
> Hey everybody,
>
> I want to come back to my question above. Any ideas on this?

The pools are not transaction managers. You you want to use a pool in
a 'with' statement you can write your subclass adding __enter__ and
__exit__ method.

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Ryan Kelly 2013-09-12 16:06:34 copy_from and rowcount
Previous Message Frank Broniewski 2013-08-27 07:13:23 Re: Connection pooling and with statement