[IPython-User] Ctrl-C to kill queries in iPython

Dave Himrod dhrod5@gmail....
Mon Nov 28 09:43:32 CST 2011

I wrote a database/connection wrapper that can connect to different types of databases (mysql, netezza, vertica and mysql).  A problem we have is that hitting ctrl-c does not necessarily kill the query, sometimes the ctrl-c interrupt isn't even handled until the query returns.  Does anyone have any experience with this?  How can I handle the sigint to stop the query? Is there a generic way for me to tell the databases to kill the queries on their end as well so it does not go zombie, I am hoping it is not specific to each db and is part of the pyodbc or mysqldb packages?  

This does not seem to work.  If i run a sleep command it waits until the sleep is over and then handles the keyboardinterrupt, seems to work differently on netezza which will kill the ipython command but the query is still running on the machine (People were not happy about that). 

            cursor = self.conn.cursor()
            cursor.execute(query, params)
            return cursor
        except KeyboardInterrupt:
            print "killing query"

I good way to test is to use the mysql sleep command

#local is a connectionwrapper that can run a query against my local mysql on the code above
local.select('select sleep(4)')    

Thanks for any advice,

More information about the IPython-User mailing list