fetchall() never returns
Rob Brown-Bayliss <[email protected]> Mon, 16 Aug 2010 13:57:39 +1200
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi
I have a problem with what appears to be fetchall() never returning or
not timing out.
I am fetching a set of results from a db continuously, that is get the
results, process, wait and then get the results again.
The problem is that randomly the fetch loop seems to just stop. No
errors, nothing at all. Some times it will run for a day or more,
other times it will stop after a couple of minutes. The database is
on the other side of the world, so there is a large round trip (600ms
or more), so I was wondering if that was the cause.
Attached is a simple test I have been using. I set the time out on
the server to 1 second, is there any way to set the time out on the
client? Or is there something else happening here. Once or twice I
have had an InternalError exception thrown, but 99% of the time it
just seems to freeze.
thanks.
from __future__ import print_function
import psycopg2 as postgres
import psycopg2.extensions
import time
conn = postgres.connect(host=" ", port="5432", user="", password=" ",
database=" ", sslmode="prefer")
cur = conn.cursor()
cur.execute('SET statement_timeout to 1000')
def time_output():
print(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
if __name__ == "__main__":
count = 0
fail = False
while fail == False:
for x in range(10):
SQL = "SELECT ptid FROM pttable ORDER BY ptid;"
res = cur.fetchall()
time.sleep(1)
count += 1
time_output()
print("total selects: ", count)
--
--
Rob