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]>
Aaron Held wrote:
> I created a hack in my app that may not be appropriate for you but....
> 
> I made an process monitor that used an activity view (I forgot the 
> details, but its in PG docs somewhere under Monitoring) to deterimine 
> the PID of the backend and then kill it from the python using the 
> command like kill the errant PID .
> 
> I wonder if the MySQL functionality is due to the client or the server?
> I often run queries from various PG tools that run away.
> 
> -Aaron
  [...]
> Murthy Kambhampaty wrote:
> > Aaron, thanks for the reply. I have been doing that, but I have several
> > Windows users and I was hoping to avoid having to (1) show them how and (2)
> > give them privileges. I guess I will, for now. Is there any chance that
> > pyPgSQL will use the libpq function "PGrequestCancel" to support killing
> > queries by closing Python is a manner similar to issuing ^C in psql?
> > 
> > Thanks,
> > 	Murthy
> >  [...]

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.

NOTE:  Successfully dispatching a cancel request does not mean the request
       will be cancelled.
-- 
____       | Billy G. Allie    | Domain....: [email protected]
|  /|      | 7436 Hartwell     | MSN.......: [email protected]
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |
signature.asc (application/pgp-signature, 2 KB)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

Aaron Held wrote:
> I created a hack in my app that may not be appropriate for you but....
> 
> I made an process monitor that used an activity view (I forgot the 
> details, but its in PG docs somewhere under Monitoring) to deterimine 
> the PID of the backend and then kill it from the python using the 
> command like kill the errant PID .
> 
> I wonder if the MySQL functionality is due to the client or the server?
> I often run queries from various PG tools that run away.
> 
> -Aaron
  [...]
> Murthy Kambhampaty wrote:
> > Aaron, thanks for the reply. I have been doing that, but I have several
> > Windows users and I was hoping to avoid having to (1) show them how and (2)
> > give them privileges. I guess I will, for now. Is there any chance that
> > pyPgSQL will use the libpq function "PGrequestCancel" to support killing
> > queries by closing Python is a manner similar to issuing ^C in psql?
> > 
> > Thanks,
> > 	Murthy
> >  [...]

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.

NOTE:  Successfully dispatching a cancel request does not mean the request
       will be cancelled.
- -- 
____       | 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+PFMnmIkMXoVVdURAsTmAJ9aopFloqHoCXy9rkVmTS/Ry+tc2QCg9tGA
qay2nN2j5JqLRtAE91L99Uc=
=xHgN
-----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.