Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
f7eaa0c6
Kaydet (Commit)
f7eaa0c6
authored
Tem 03, 2014
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #21755: Skip {Frozen,Source}_DeadlockAvoidanceTests tests when
Python is built without threads.
üst
748ff8bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
66 deletions
+78
-66
test_locks.py
Lib/test/test_importlib/test_locks.py
+78
-66
No files found.
Lib/test/test_importlib/test_locks.py
Dosyayı görüntüle @
f7eaa0c6
...
@@ -52,74 +52,86 @@ else:
...
@@ -52,74 +52,86 @@ else:
pass
pass
@unittest.skipUnless
(
threading
,
"threads needed for this test"
)
if
threading
is
not
None
:
class
DeadlockAvoidanceTests
:
class
DeadlockAvoidanceTests
:
def
setUp
(
self
):
def
setUp
(
self
):
try
:
self
.
old_switchinterval
=
sys
.
getswitchinterval
()
sys
.
setswitchinterval
(
0.000001
)
except
AttributeError
:
self
.
old_switchinterval
=
None
def
tearDown
(
self
):
if
self
.
old_switchinterval
is
not
None
:
sys
.
setswitchinterval
(
self
.
old_switchinterval
)
def
run_deadlock_avoidance_test
(
self
,
create_deadlock
):
NLOCKS
=
10
locks
=
[
self
.
LockType
(
str
(
i
))
for
i
in
range
(
NLOCKS
)]
pairs
=
[(
locks
[
i
],
locks
[(
i
+
1
)
%
NLOCKS
])
for
i
in
range
(
NLOCKS
)]
if
create_deadlock
:
NTHREADS
=
NLOCKS
else
:
NTHREADS
=
NLOCKS
-
1
barrier
=
threading
.
Barrier
(
NTHREADS
)
results
=
[]
def
_acquire
(
lock
):
"""Try to acquire the lock. Return True on success, False on deadlock."""
try
:
try
:
lock
.
acquire
()
self
.
old_switchinterval
=
sys
.
getswitchinterval
()
except
self
.
DeadlockError
:
sys
.
setswitchinterval
(
0.000001
)
return
False
except
AttributeError
:
self
.
old_switchinterval
=
None
def
tearDown
(
self
):
if
self
.
old_switchinterval
is
not
None
:
sys
.
setswitchinterval
(
self
.
old_switchinterval
)
def
run_deadlock_avoidance_test
(
self
,
create_deadlock
):
NLOCKS
=
10
locks
=
[
self
.
LockType
(
str
(
i
))
for
i
in
range
(
NLOCKS
)]
pairs
=
[(
locks
[
i
],
locks
[(
i
+
1
)
%
NLOCKS
])
for
i
in
range
(
NLOCKS
)]
if
create_deadlock
:
NTHREADS
=
NLOCKS
else
:
else
:
return
True
NTHREADS
=
NLOCKS
-
1
def
f
():
barrier
=
threading
.
Barrier
(
NTHREADS
)
a
,
b
=
pairs
.
pop
()
results
=
[]
ra
=
_acquire
(
a
)
barrier
.
wait
()
def
_acquire
(
lock
):
rb
=
_acquire
(
b
)
"""Try to acquire the lock. Return True on success,
results
.
append
((
ra
,
rb
))
False on deadlock."""
if
rb
:
try
:
b
.
release
()
lock
.
acquire
()
if
ra
:
except
self
.
DeadlockError
:
a
.
release
()
return
False
lock_tests
.
Bunch
(
f
,
NTHREADS
)
.
wait_for_finished
()
else
:
self
.
assertEqual
(
len
(
results
),
NTHREADS
)
return
True
return
results
def
f
():
def
test_deadlock
(
self
):
a
,
b
=
pairs
.
pop
()
results
=
self
.
run_deadlock_avoidance_test
(
True
)
ra
=
_acquire
(
a
)
# At least one of the threads detected a potential deadlock on its
barrier
.
wait
()
# second acquire() call. It may be several of them, because the
rb
=
_acquire
(
b
)
# deadlock avoidance mechanism is conservative.
results
.
append
((
ra
,
rb
))
nb_deadlocks
=
results
.
count
((
True
,
False
))
if
rb
:
self
.
assertGreaterEqual
(
nb_deadlocks
,
1
)
b
.
release
()
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
)
-
nb_deadlocks
)
if
ra
:
a
.
release
()
def
test_no_deadlock
(
self
):
lock_tests
.
Bunch
(
f
,
NTHREADS
)
.
wait_for_finished
()
results
=
self
.
run_deadlock_avoidance_test
(
False
)
self
.
assertEqual
(
len
(
results
),
NTHREADS
)
self
.
assertEqual
(
results
.
count
((
True
,
False
)),
0
)
return
results
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
))
def
test_deadlock
(
self
):
results
=
self
.
run_deadlock_avoidance_test
(
True
)
DEADLOCK_ERRORS
=
{
kind
:
splitinit
.
_bootstrap
.
_DeadlockError
# At least one of the threads detected a potential deadlock on its
for
kind
,
splitinit
in
init
.
items
()}
# second acquire() call. It may be several of them, because the
# deadlock avoidance mechanism is conservative.
(
Frozen_DeadlockAvoidanceTests
,
nb_deadlocks
=
results
.
count
((
True
,
False
))
Source_DeadlockAvoidanceTests
self
.
assertGreaterEqual
(
nb_deadlocks
,
1
)
)
=
test_util
.
test_both
(
DeadlockAvoidanceTests
,
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
)
-
nb_deadlocks
)
LockType
=
LOCK_TYPES
,
DeadlockError
=
DEADLOCK_ERRORS
)
def
test_no_deadlock
(
self
):
results
=
self
.
run_deadlock_avoidance_test
(
False
)
self
.
assertEqual
(
results
.
count
((
True
,
False
)),
0
)
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
))
DEADLOCK_ERRORS
=
{
kind
:
splitinit
.
_bootstrap
.
_DeadlockError
for
kind
,
splitinit
in
init
.
items
()}
(
Frozen_DeadlockAvoidanceTests
,
Source_DeadlockAvoidanceTests
)
=
test_util
.
test_both
(
DeadlockAvoidanceTests
,
LockType
=
LOCK_TYPES
,
DeadlockError
=
DEADLOCK_ERRORS
)
else
:
DEADLOCK_ERRORS
=
{}
class
Frozen_DeadlockAvoidanceTests
(
unittest
.
TestCase
):
pass
class
Source_DeadlockAvoidanceTests
(
unittest
.
TestCase
):
pass
class
LifetimeTests
:
class
LifetimeTests
:
...
...
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