Created
July 3, 2012 01:45
-
-
Save zmsmith/3037007 to your computer and use it in GitHub Desktop.
Django - Kill Queries Matching a RegEx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kill_queries(query='', db_alias='default'): | |
from django.db import connections | |
import re | |
connection = connections[db_alias] | |
cursor = connection.cursor() | |
cursor.execute("SHOW PROCESSLIST") | |
for row in cursor.fetchall(): | |
current = row[-1] | |
if current and re.search(query, current): | |
proc_id = row[0] | |
kill = "KILL {}".format(proc_id) | |
try: | |
cursor.execute(kill) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment