Re: Re: How to stop query execution from Python/pyPgS QL

"Billy G. Allie" <[email protected]>
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Gerhard =?iso-8859-1?Q?H=E4ring?= wrote:
> Billy G. Allie <[email protected]> wrote:
> > [cancelling a query]
> > Since PgSQL is built upon the libpq module, you can access the
> > PGrequestCancel function as follows (assuming 'cx' is the connection
> > running the request you wish to cancel):
> > 
> > 	cx.conn.requestCancel()
> > 
> > This would have to be issued by a different thread of execution or from a
> > signal handler since the execute method does not return until the query
> > has finished processing at the backend.
> 
> Can this work? I was under the impression that this was one of the functions
> that's supposed to be used under the asynchronous API.
> 
> Incidentally, I've tried to use the async functions in pyPgSQL.libpq a few
> days back (and cancelling a query), but didn't succeed.  Today, I've found
> out why and committed a change to pgconnection.c. I believe you'll have to
> use the CVS version of pyPgSQL to cancel queries for now.
> 
> Here's a toy example with which I tested this functionality:
> [...]
> ciao,
> 
> Gerhard

You should be able to send the cancel request from a signal handler.  I don't 
think (now) that it can be issued in a different thread.  Here is the relevant 
part of the PostgreSQL manual:

"PQrequestCancel can safely be invoked from a signal handler. So, it is also 
possible to use it in conjunction with plain PQexec, if the decision to cancel 
can be made in a signal handler. For example, psql invokes PQrequestCancel 
from a SIGINT signal handler, thus allowing interactive cancellation of 
queries that it issues through PQexec. Note that PQrequestCancel will have no 
effect if the connection is not currently open or the backend is not currently 
processing a command."

Later.


-- 
____       | Billy G. Allie    | Domain....: [email protected]
|  /|      | 7436 Hartwell     | MSN.......: [email protected]
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |
signature.asc (application/pgp-signature, 2.3 KB)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Content-Type: text/plain; charset=us-ascii

Gerhard =?iso-8859-1?Q?H=E4ring?= wrote:
> Billy G. Allie <[email protected]> wrote:
> > [cancelling a query]
> > Since PgSQL is built upon the libpq module, you can access the
> > PGrequestCancel function as follows (assuming 'cx' is the connection
> > running the request you wish to cancel):
> > 
> > 	cx.conn.requestCancel()
> > 
> > This would have to be issued by a different thread of execution or from a
> > signal handler since the execute method does not return until the query
> > has finished processing at the backend.
> 
> Can this work? I was under the impression that this was one of the functions
> that's supposed to be used under the asynchronous API.
> 
> Incidentally, I've tried to use the async functions in pyPgSQL.libpq a few
> days back (and cancelling a query), but didn't succeed.  Today, I've found
> out why and committed a change to pgconnection.c. I believe you'll have to
> use the CVS version of pyPgSQL to cancel queries for now.
> 
> Here's a toy example with which I tested this functionality:
> [...]
> ciao,
> 
> Gerhard

You should be able to send the cancel request from a signal handler.  I don't 
think (now) that it can be issued in a different thread.  Here is the relevant 
part of the PostgreSQL manual:

"PQrequestCancel can safely be invoked from a signal handler. So, it is also 
possible to use it in conjunction with plain PQexec, if the decision to cancel 
can be made in a signal handler. For example, psql invokes PQrequestCancel 
from a SIGINT signal handler, thus allowing interactive cancellation of 
queries that it issues through PQexec. Note that PQrequestCancel will have no 
effect if the connection is not currently open or the backend is not currently 
processing a command."

Later.


- -- 
____       | Billy G. Allie    | Domain....: [email protected]
|  /|      | 7436 Hartwell     | MSN.......: [email protected]
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.2 (UnixWare)
Comment: Exmh version 2.2 06/23/2000

iD8DBQE9+ruOnmIkMXoVVdURAiBtAJ9ozjSoAVnPBs7ZFWlyWsKy150zGgCgy0o7
BXnIdHt1LvSOQr2WyDwDOjo=
=VZv7
-----END PGP SIGNATURE-----
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.