mirror of
https://github.com/django/django.git
synced 2025-08-06 03:48:38 +00:00
Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.
Thanks Tim Martin for review.
This commit is contained in:
parent
7bbb5161ea
commit
66150f7cf6
2 changed files with 21 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue