Re: fetchall() never returns
Daniele Varrazzo <[email protected]> Mon, 16 Aug 2010 08:33:04 +0100
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Aug 16, 2010 at 2:57 AM, Rob Brown-Bayliss <[email protected]> wrote: > Hi > > I have a problem with what appears to be fetchall() never returning or > not timing out. Can you see what is happening in the server while the query is running? E.g. you can execute a "select * from pg_stat_activity" in a separate connection and check if your query appears there. In order to cancel a running query you may execute the pg_cancel_backend function(pid) [1] in another connection, using as pid the one returned by conn.get_backend_pid() [2] on the connection to time out (retrieved before running the query of course) Because python is stuck with the execute, you may need a separate thread to send the cancel, otherwise you may try with a signal: see for instance the recipe [3]. [1] http://www.postgresql.org/docs/8.3/static/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE [2] http://initd.org/psycopg/docs/connection.html#connection.get_backend_pid [3] http://stackoverflow.com/questions/492519/timeout-on-a-python-function-call/494273#494273 -- Daniele