summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/client.py
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2022-05-20 07:11:51 +0200
committerGitHub <noreply@github.com>2022-05-20 07:11:51 +0200
commit1a78ef2b85467a18ea6d7eaa4b27f67d11c87b9e (patch)
treea09504d830f8102004e3ab6828efd5892f160429 /django/db/backends/mysql/client.py
parente89f9571352f42c7752b351ba1e651485e5e7c51 (diff)
downloaddjango-1a78ef2b85467a18ea6d7eaa4b27f67d11c87b9e.tar.gz
Fixed #33715 -- Allowed keyboard interrupt to abort queries in MySQL dbshell.
Diffstat (limited to 'django/db/backends/mysql/client.py')
-rw-r--r--django/db/backends/mysql/client.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/backends/mysql/client.py b/django/db/backends/mysql/client.py
index 0c09a2ca1e..6aa11b2e1f 100644
--- a/django/db/backends/mysql/client.py
+++ b/django/db/backends/mysql/client.py
@@ -1,3 +1,5 @@
+import signal
+
from django.db.backends.base.client import BaseDatabaseClient
@@ -58,3 +60,13 @@ class DatabaseClient(BaseDatabaseClient):
args += [database]
args.extend(parameters)
return args, env
+
+ def runshell(self, parameters):
+ sigint_handler = signal.getsignal(signal.SIGINT)
+ try:
+ # Allow SIGINT to pass to mysql to abort queries.
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
+ super().runshell(parameters)
+ finally:
+ # Restore the original SIGINT handler.
+ signal.signal(signal.SIGINT, sigint_handler)