New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queries unresponsive to SIGINT / Keyboard-interupt in Interactive Shell #333
Comments
I don't think we can do anything about that. What you can do is ctrl-z and then kill the script, or pg_cancel_backend() the session to stop the query. |
This doesn't happen with any other python database adapter. The user should be able to interrupt a hung connection with SIGINT. edit: I would be willing to work on this - but imho this issue needs to be reopened - I really don't think this kind of bug is reasonable to accept as "working as normal" in what is probably the most popular python postgres library especially given that no other libraries (at least that I have used) exhibit the above behaviour. |
If you find a solution please feel free to contribute. I will leave this bug open for some time and will close it if I don't find any activity on it. Note that in green mode you should find the queries easier to interrupt:
but in normal mode the waiting is done by the libpq and I don't know how to send it messages. By the way the above trashes the connection. |
Hello Daniele, Thanks for opening this back up. So I don't know the library very well but looking at the async foremost - it seems the problem is how it is handled in green.c? Specifically there are only two exit paths - either if (0 != psyco_wait(conn)) {
green_panic(conn);
goto end;
}
/* Now we can read the data without fear of blocking. */
result = pq_get_last_result(conn); It would be nice to give a clean exit path from psyco_wait which doesn't trash the connection (i.e. trying PQcancel first). And/or allowing an on_wait_exit hook or something of the like to happen before the entire call blocks on Basically with the current behaviour if I handle an exception within a custom wait callback (e.g. |
you could try running Actually, I went to google for connection cancel to make sure of the function name and I discovered an article about cancelling a query from Python. Written by me one year ago. Wow, I'm growing old :( http://initd.org/psycopg/articles/2014/07/20/cancelling-postgresql-statements-python/ |
@dvarrazzo Would be great if this could make it into the docs or extensions.py. |
It could be a FAQ entry, yes. Feel free to propose a patch, the way you would have liked to find in the docs, thanks. |
I have fixed the |
SIGINT to dbmigrator is ignored while psycopg2 is running a sql statement. See psycopg/psycopg2#333
SIGINT to dbmigrator is ignored while psycopg2 is running a sql statement. See psycopg/psycopg2#333
For people finding this from the Internet, on recent versions of the library, use this:
|
We use the PsycoPG2 "wait select" callback to pass through Ctrl-C events to the backend. This seems to set up some sort of polling that throws warnings from time to time, but these seem not to matter. See psycopg/psycopg2#333 for more information.
Overly intensive queries or queries on a hung-connection are entirely unresponsive to keyboard-interrupt and require a very, very long wait for timeout or termination of the current interactive shell.
*Python 3.4.3, Linux 4.0.4 / Mac OS X 10.10
The text was updated successfully, but these errors were encountered: