2

Is there a way to let the user stop the execution of a sql query in python if it takes some long time? I am thinking of using a progress bar with a cancel button, but I wonder if there is a way to stop it in a clean way instead of killing abruptly the associated thread? (I am using both pysqlite2 and MySQLdb packages)

banx
  • 4,376
  • 4
  • 30
  • 34
  • 1
    I think you'd be better off addressing why the query is taking so long – OMG Ponies Aug 07 '10 at 17:54
  • @OMG_Ponies: Usually the queries doesn't take much time, but for instance, I have a query that is taking more than 100 sec that involves some sorting and grouping of around a million rows. – banx Aug 07 '10 at 18:32

1 Answers1

3

the only solution i see is to get the process id:

SHOW PROCESSLIST;

and kill it:

KILL <thread_id>;

i would execute those commands with mysqldb.

However, you should be carefull about the rollback. See for example: If I stop a long running query, does it rollback?

hope it helps

Community
  • 1
  • 1
Mermoz
  • 14,898
  • 17
  • 60
  • 85