diff options
author | Chris Sinchok <chris@sinchok.com> | 2017-04-01 20:01:08 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-04-01 21:01:08 -0400 |
commit | 66150f7cf61bc09547fa98586790df596eff6d77 (patch) | |
tree | 231233c290ab6d51ef123a1f9dc2033be24fe5d8 /django/db/backends/postgresql/client.py | |
parent | 7bbb5161eaad6771676281c5c544030cf9ff1312 (diff) | |
download | django-66150f7cf61bc09547fa98586790df596eff6d77.tar.gz |
Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.
Thanks Tim Martin for review.
Diffstat (limited to 'django/db/backends/postgresql/client.py')
-rw-r--r-- | django/db/backends/postgresql/client.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py index 005f43ddb8..466c2986d2 100644 --- a/django/db/backends/postgresql/client.py +++ b/django/db/backends/postgresql/client.py @@ -1,4 +1,5 @@ import os +import signal import subprocess from django.core.files.temp import NamedTemporaryFile @@ -34,6 +35,7 @@ class DatabaseClient(BaseDatabaseClient): args += [dbname] temp_pgpass = None + sigint_handler = signal.getsignal(signal.SIGINT) try: if passwd: # Create temporary .pgpass file. @@ -54,8 +56,12 @@ class DatabaseClient(BaseDatabaseClient): # If the current locale can't encode the data, we let # the user input the password manually. pass + # Allow SIGINT to pass to psql to abort queries. + signal.signal(signal.SIGINT, signal.SIG_IGN) subprocess.check_call(args) finally: + # Restore the orignal SIGINT handler. + signal.signal(signal.SIGINT, sigint_handler) if temp_pgpass: temp_pgpass.close() if 'PGPASSFILE' in os.environ: # unit tests need cleanup |