Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
66150f7c
Kaydet (Commit)
66150f7c
authored
Nis 02, 2017
tarafından
Chris Sinchok
Kaydeden (comit)
Tim Graham
Nis 02, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.
Thanks Tim Martin for review.
üst
7bbb5161
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
client.py
django/db/backends/postgresql/client.py
+6
-0
test_postgresql_psycopg2.py
tests/dbshell/test_postgresql_psycopg2.py
+15
-0
No files found.
django/db/backends/postgresql/client.py
Dosyayı görüntüle @
66150f7c
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
...
...
tests/dbshell/test_postgresql_psycopg2.py
Dosyayı görüntüle @
66150f7c
import
os
import
signal
from
unittest
import
mock
from
django.db.backends.postgresql.client
import
DatabaseClient
...
...
@@ -99,3 +100,17 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase):
pgpass_string
,
)
)
def
test_sigint_handler
(
self
):
"""SIGINT is ignored in Python and passed to psql to abort quries."""
def
_mock_subprocess_call
(
*
args
):
handler
=
signal
.
getsignal
(
signal
.
SIGINT
)
self
.
assertEqual
(
handler
,
signal
.
SIG_IGN
)
sigint_handler
=
signal
.
getsignal
(
signal
.
SIGINT
)
# The default handler isn't SIG_IGN.
self
.
assertNotEqual
(
sigint_handler
,
signal
.
SIG_IGN
)
with
mock
.
patch
(
'subprocess.check_call'
,
new
=
_mock_subprocess_call
):
DatabaseClient
.
runshell_db
({})
# dbshell restores the orignal handler.
self
.
assertEqual
(
sigint_handler
,
signal
.
getsignal
(
signal
.
SIGINT
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment