[Web-SIG] Closing long-running WSGI requests (possible?)
manlio_perillo at libero.it
Mon Apr 13 23:58:48 CEST 2009
Chimezie Ogbuji ha scritto:
> Hello. I have a problem with a WSGI-based SPARQL server that I have been
> unable to resolve for some time. I was told this is the best place to ask
> :). I'm building a SPARQL  server that is deployed as WSGI/Paste
> server. SPARQL queries are handled by the server and evaluated against a
> MySQL database using mysql-python/MySQLdb to manage the connection.
> My goal is to be able to allow clients to close the connection in order to
> kill queries that have been dispatched (in order to 'abort' them).
> Unfortunately, when the client kills the connection, the application is not
> signaled in any way. So, the result is that (for long-running queries), the
> MySQL query continues to run even after the connection is closed (by
> clicking cancel in the browser for instance).
What you want to do is not possible.
Add a custom "abort button" on the web page so that a function is
associate to the "click" event.
Also, you should associate a function to the "unload" event (where you
can check if there are active queries).
Note that if you use PostgreSQL, you can use:
When you create a connection to PostgreSQL, the server will send you the
backend process id an unique key.
You can use this data to send a cancellation request.
All you need to do is to pass the process id and the unique key to the
client (with some encryption so that the client can use the data only once).
Unfortunately, libpq does not offer a flexible interface to this feature.
The PGCancel structure is opaque, so you need some hacking.
More information about the Web-SIG