I\'m trying to enforce a time limit on queries in python MySQLDB. I have a situation where I have no control over the queries, but need to ensure that they do not run over a
Why do I not get the signal until after execute finishes?
The query is executed through a C function, which blocks the Python VM from executing until it returns.
Is there another reliable way to limit query execution time?
This is (IMO) a really ugly solution, but it does work. You could run the query in a separate process (either via fork()
or the multiprocessing module). Run the alarm timer in your main process, and when you receive it, send a SIGINT
or SIGKILL
to the child process. If you use multiprocessing
, you can use the Process.terminate()
method.