Skip site navigation (1) Skip section navigation (2)

Re: psycopg2 (async) socket timeout

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Danny Milosavljevic <danny(dot)milo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: psycopg2 (async) socket timeout
Date: 2011-02-03 20:35:50
Message-ID: AANLkTin3inFX=0wXSwEo9xEUnc8sRM_xBX=7T1iW81yR@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
On Thu, Feb 3, 2011 at 8:04 PM, Danny Milosavljevic
<danny(dot)milo(at)gmail(dot)com> wrote:
> Hello,
>
> is it possible to specify the timeout for the socket underlying a connection?

You can send a command SET statement_timeout to affect all the
commands further sent to the connection

http://www.postgresql.org/docs/9.0/static/runtime-config-client.html#GUC-STATEMENT-TIMEOUT


> Alternatively, since I'm using the async interface anyway, is it
> possible proactively cancel a query that is "stuck" since the TCP
> connection to the database is down?

Jan has contributed a connection.cancel() method, available since psycopg 2.3

http://initd.org/psycopg/docs/connection.html#connection.cancel


> So the specific case is:
> - connect to the postgres database using psycopg2 while network is up
> - run some queries, get the results fine etc
> - send a query
> - the network goes down before the result to this last query has been received
> - neither a result nor an error callback gets called - as far as I can
> see (using txpostgres.ConnectionPool)
>
> What's the proper way to deal with that?

Probably canceling the query from the client: if the network is down
you wouldn't get the signal that the backend timed out. But I've never
dealt with this scenario myself so I guess you should test if any of
the above works for you :)

-- Daniele

In response to

psycopg by date

Next:From: Federico Di GregorioDate: 2011-02-06 16:26:51
Subject: RELEASE: 2.4 beta 1
Previous:From: Danny MilosavljevicDate: 2011-02-03 20:04:39
Subject: psycopg2 (async) socket timeout

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group