From: Billy G. A. <bg...@mu...> - 2002-12-14 05:03:29
|
Gerhard =?iso-8859-1?Q?H=E4ring?= wrote: > Billy G. Allie <bga=Ndj...@pu...> 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....: Bil...@mu... | /| | 7436 Hartwell | MSN.......: B_G...@em... |-/-|----- | Dearborn, MI 48126| |/ |LLIE | (313) 582-1540 | |