Re: Stuck connection/query?

Jan UrbaƄski <[email protected]> Wed, 16 Jun 2010 23:54:47 +0200
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On 15/06/10 23:43, Brien Voorhees wrote:
> Greetings,
> I have a long-running python program that continually cycles through a
> list of servers and queries them to retrieve data.  Occasionally (every
> few days) it will get stuck in a pyscopg2 function call.   For
> reference, the program is running on linux and using psycopg2 2.0.14
> with python 2.6.
> 
> I've seen it get stuck in both cur.execute() and also in
> pyscopg2.connect().   I'm guessing it's due to some network error or an
> unresponsive postgres server.
> 
> Is there any way to specify a timeout or some other recommended solution?

Depends if you are waiting for the network to respond or for the
database to finish processing.

If it's the former, you will have to add timeouts in your code. If your
problem are queries that take too long then you can look at the
statement_timeout parameter on PostgreSQL, but even then you should
probably have some timeouts in the app code (implementing which is
outside of the scope of psycopg2).

Cheers,
Jan