Discussion:
Stuck connection/query?
Brien Voorhees
2010-06-15 21:43:47 UTC
Permalink
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?

Thanks
-Brien
Jan Urbański
2010-06-16 21:54:47 UTC
Permalink
Post by Brien Voorhees
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

Loading...