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
1f9dea0b
Kaydet (Commit)
1f9dea0b
authored
Tem 14, 2010
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9251: test_threaded_import didn't fail when run through regrtest
if the import lock was disabled.
üst
aa69d4d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
55 deletions
+53
-55
test_threaded_import.py
Lib/test/test_threaded_import.py
+50
-55
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_threaded_import.py
Dosyayı görüntüle @
1f9dea0b
...
@@ -5,72 +5,67 @@
...
@@ -5,72 +5,67 @@
# complains several times about module random having no attribute
# complains several times about module random having no attribute
# randrange, and then Python hangs.
# randrange, and then Python hangs.
import
imp
import
sys
import
unittest
import
unittest
from
test.support
import
verbose
,
TestFailed
,
import_module
from
test.support
import
verbose
,
TestFailed
,
import_module
,
run_unittest
thread
=
import_module
(
'_thread'
)
thread
=
import_module
(
'_thread'
)
critical_section
=
thread
.
allocate_lock
()
def
task
(
N
,
done
,
done_tasks
,
errors
):
done
=
thread
.
allocate_lock
()
def
task
():
global
N
,
critical_section
,
done
import
random
x
=
random
.
randrange
(
1
,
3
)
critical_section
.
acquire
()
N
-=
1
# Must release critical_section before releasing done, else the main
# thread can exit and set critical_section to None as part of global
# teardown; then critical_section.release() raises AttributeError.
finished
=
N
==
0
critical_section
.
release
()
if
finished
:
done
.
release
()
def
test_import_hangers
():
import
sys
if
verbose
:
print
(
"testing import hangers ..."
,
end
=
' '
)
import
test.threaded_import_hangers
try
:
try
:
if
test
.
threaded_import_hangers
.
errors
:
import
random
raise
TestFailed
(
test
.
threaded_import_hangers
.
errors
)
# This will fail if random is not completely initialized
elif
verbose
:
x
=
random
.
randrange
(
1
,
3
)
print
(
"OK."
)
except
Exception
as
e
:
errors
.
append
(
e
.
with_traceback
(
None
))
finally
:
finally
:
# In case this test is run again, make sure the helper module
done_tasks
.
append
(
thread
.
get_ident
())
# gets loaded from scratch again.
finished
=
len
(
done_tasks
)
==
N
del
sys
.
modules
[
'test.threaded_import_hangers'
]
if
finished
:
done
.
release
()
# Tricky: When regrtest imports this module, the thread running regrtest
# grabs the import lock and won't let go of it until this module returns.
# All other threads attempting an import hang for the duration. Since
# this test spawns threads that do little *but* import, we can't do that
# successfully until after this module finishes importing and regrtest
# regains control. To make this work, a special case was added to
# regrtest to invoke a module's "test_main" function (if any) after
# importing it.
def
test_main
():
# magic name! see above
class
ThreadedImportTests
(
unittest
.
TestCase
):
global
N
,
done
import
imp
def
test_parallel_module_init
(
self
):
if
imp
.
lock_held
():
if
imp
.
lock_held
():
# This triggers on, e.g., from test import autotest.
# This triggers on, e.g., from test import autotest.
raise
unittest
.
SkipTest
(
"can't run when import lock is held"
)
raise
unittest
.
SkipTest
(
"can't run when import lock is held"
)
done
.
acquire
()
done
=
thread
.
allocate_lock
()
for
N
in
(
20
,
50
)
*
3
:
if
verbose
:
print
(
"Trying"
,
N
,
"threads ..."
,
end
=
' '
)
for
i
in
range
(
N
):
thread
.
start_new_thread
(
task
,
())
done
.
acquire
()
done
.
acquire
()
if
verbose
:
for
N
in
(
20
,
50
)
*
3
:
print
(
"OK."
)
if
verbose
:
done
.
release
()
print
(
"Trying"
,
N
,
"threads ..."
,
end
=
' '
)
# Make sure that random gets reimported freshly
try
:
del
sys
.
modules
[
'random'
]
except
KeyError
:
pass
errors
=
[]
done_tasks
=
[]
for
i
in
range
(
N
):
thread
.
start_new_thread
(
task
,
(
N
,
done
,
done_tasks
,
errors
,))
done
.
acquire
()
self
.
assertFalse
(
errors
)
if
verbose
:
print
(
"OK."
)
done
.
release
()
def
test_import_hangers
(
self
):
# In case this test is run again, make sure the helper module
# gets loaded from scratch again.
try
:
del
sys
.
modules
[
'test.threaded_import_hangers'
]
except
KeyError
:
pass
import
test.threaded_import_hangers
self
.
assertFalse
(
test
.
threaded_import_hangers
.
errors
)
def
test_main
():
run_unittest
(
ThreadedImportTests
)
test_import_hangers
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
Misc/NEWS
Dosyayı görüntüle @
1f9dea0b
...
@@ -1650,6 +1650,9 @@ Documentation
...
@@ -1650,6 +1650,9 @@ Documentation
Tests
Tests
-----
-----
- Issue #9251: test_threaded_import didn't fail when run through regrtest
if the import lock was disabled.
- Issue #8605: Skip test_gdb if Python is compiled with optimizations.
- Issue #8605: Skip test_gdb if Python is compiled with optimizations.
- Issue #7449: Skip test_socketserver if threading support is disabled
- Issue #7449: Skip test_socketserver if threading support is disabled
...
...
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