Re: stop a long running select

James Henstridge <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Fri, May 1, 2009 at 9:29 PM, johnf <jfabiani-rLSQ/[email protected]> wrote:
> Hi,
> Is there a way to stop a long running select statement without losing the
> connection, cursor from python?

There is a connection variable called statement_timeout, which you can
use to set the maximum length of time any particular statement issued
can take in milliseconds.

So if you issue the command "SET statement_timeout TO 1000", and then
a subsequent execute() call takes longer than 1 second, you'll get a
psycopg2.extensions.QueryCanceledError exception.  At that point you
can roll back the connection and do what ever recovery is appropriate
for your application.

The transaction will have failed, but that is unavoidable: a query
being canceled is the same as a query that fails.

James.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.