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
c4d7864e
Kaydet (Commit)
c4d7864e
authored
May 05, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use shared testing facilities in test_threading
üst
66a18fd8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
47 deletions
+18
-47
test_threading.py
Lib/test/test_threading.py
+18
-47
No files found.
Lib/test/test_threading.py
Dosyayı görüntüle @
c4d7864e
# Very rudimentary test of threading module
# Very rudimentary test of threading module
import
test.support
import
test.support
from
test.support
import
verbose
,
strip_python_stderr
from
test.support
import
verbose
,
strip_python_stderr
,
import_module
import
random
import
random
import
re
import
re
import
sys
import
sys
_thread
=
test
.
support
.
import_module
(
'_thread'
)
_thread
=
import_module
(
'_thread'
)
threading
=
test
.
support
.
import_module
(
'threading'
)
threading
=
import_module
(
'threading'
)
import
time
import
time
import
unittest
import
unittest
import
weakref
import
weakref
import
os
import
os
import
subprocess
from
test.script_helper
import
assert_python_ok
,
assert_python_failure
from
test.script_helper
import
assert_python_ok
from
test
import
lock_tests
from
test
import
lock_tests
...
@@ -163,10 +162,7 @@ class ThreadTests(BaseTestCase):
...
@@ -163,10 +162,7 @@ class ThreadTests(BaseTestCase):
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
# exposed at the Python level. This test relies on ctypes to get at it.
# exposed at the Python level. This test relies on ctypes to get at it.
def
test_PyThreadState_SetAsyncExc
(
self
):
def
test_PyThreadState_SetAsyncExc
(
self
):
try
:
ctypes
=
import_module
(
"ctypes"
)
import
ctypes
except
ImportError
:
raise
unittest
.
SkipTest
(
"cannot import ctypes"
)
set_async_exc
=
ctypes
.
pythonapi
.
PyThreadState_SetAsyncExc
set_async_exc
=
ctypes
.
pythonapi
.
PyThreadState_SetAsyncExc
...
@@ -269,12 +265,9 @@ class ThreadTests(BaseTestCase):
...
@@ -269,12 +265,9 @@ class ThreadTests(BaseTestCase):
# Issue 1402: the PyGILState_Ensure / _Release functions may be called
# Issue 1402: the PyGILState_Ensure / _Release functions may be called
# very late on python exit: on deallocation of a running thread for
# very late on python exit: on deallocation of a running thread for
# example.
# example.
try
:
import_module
(
"ctypes"
)
import
ctypes
except
ImportError
:
raise
unittest
.
SkipTest
(
"cannot import ctypes"
)
rc
=
subprocess
.
call
([
sys
.
executable
,
"-c"
,
"""if 1:
rc
,
out
,
err
=
assert_python_failure
(
"-c"
,
"""if 1:
import ctypes, sys, time, _thread
import ctypes, sys, time, _thread
# This lock is used as a simple event variable.
# This lock is used as a simple event variable.
...
@@ -298,13 +291,13 @@ class ThreadTests(BaseTestCase):
...
@@ -298,13 +291,13 @@ class ThreadTests(BaseTestCase):
_thread.start_new_thread(waitingThread, ())
_thread.start_new_thread(waitingThread, ())
ready.acquire() # Be sure the other thread is waiting.
ready.acquire() # Be sure the other thread is waiting.
sys.exit(42)
sys.exit(42)
"""
]
)
"""
)
self
.
assertEqual
(
rc
,
42
)
self
.
assertEqual
(
rc
,
42
)
def
test_finalize_with_trace
(
self
):
def
test_finalize_with_trace
(
self
):
# Issue1733757
# Issue1733757
# Avoid a deadlock when sys.settrace steps into threading._shutdown
# Avoid a deadlock when sys.settrace steps into threading._shutdown
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"""if 1:
assert_python_ok
(
"-c"
,
"""if 1:
import sys, threading
import sys, threading
# A deadlock-killer, to prevent the
# A deadlock-killer, to prevent the
...
@@ -324,21 +317,12 @@ class ThreadTests(BaseTestCase):
...
@@ -324,21 +317,12 @@ class ThreadTests(BaseTestCase):
return func
return func
sys.settrace(func)
sys.settrace(func)
"""
],
"""
)
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdout
.
close
)
self
.
addCleanup
(
p
.
stderr
.
close
)
stdout
,
stderr
=
p
.
communicate
()
rc
=
p
.
returncode
self
.
assertFalse
(
rc
==
2
,
"interpreted was blocked"
)
self
.
assertTrue
(
rc
==
0
,
"Unexpected error: "
+
ascii
(
stderr
))
def
test_join_nondaemon_on_shutdown
(
self
):
def
test_join_nondaemon_on_shutdown
(
self
):
# Issue 1722344
# Issue 1722344
# Raising SystemExit skipped threading._shutdown
# Raising SystemExit skipped threading._shutdown
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"""if 1:
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
"""if 1:
import threading
import threading
from time import sleep
from time import sleep
...
@@ -350,16 +334,10 @@ class ThreadTests(BaseTestCase):
...
@@ -350,16 +334,10 @@ class ThreadTests(BaseTestCase):
threading.Thread(target=child).start()
threading.Thread(target=child).start()
raise SystemExit
raise SystemExit
"""
],
"""
)
stdout
=
subprocess
.
PIPE
,
self
.
assertEqual
(
out
.
strip
(),
stderr
=
subprocess
.
PIPE
)
self
.
addCleanup
(
p
.
stdout
.
close
)
self
.
addCleanup
(
p
.
stderr
.
close
)
stdout
,
stderr
=
p
.
communicate
()
self
.
assertEqual
(
stdout
.
strip
(),
b
"Woke up, sleep function is: <built-in function sleep>"
)
b
"Woke up, sleep function is: <built-in function sleep>"
)
stderr
=
strip_python_stderr
(
stderr
)
self
.
assertEqual
(
err
,
b
""
)
self
.
assertEqual
(
stderr
,
b
""
)
def
test_enumerate_after_join
(
self
):
def
test_enumerate_after_join
(
self
):
# Try hard to trigger #1703448: a thread is still returned in
# Try hard to trigger #1703448: a thread is still returned in
...
@@ -444,13 +422,9 @@ class ThreadJoinOnShutdown(BaseTestCase):
...
@@ -444,13 +422,9 @@ class ThreadJoinOnShutdown(BaseTestCase):
sys.stdout.flush()
sys.stdout.flush()
\n
"""
+
script
\n
"""
+
script
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
script
],
stdout
=
subprocess
.
PIPE
)
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
script
)
rc
=
p
.
wait
()
data
=
out
.
decode
()
.
replace
(
'
\r
'
,
''
)
data
=
p
.
stdout
.
read
()
.
decode
()
.
replace
(
'
\r
'
,
''
)
p
.
stdout
.
close
()
self
.
assertEqual
(
data
,
"end of main
\n
end of thread
\n
"
)
self
.
assertEqual
(
data
,
"end of main
\n
end of thread
\n
"
)
self
.
assertFalse
(
rc
==
2
,
"interpreter was blocked"
)
self
.
assertTrue
(
rc
==
0
,
"Unexpected error"
)
def
test_1_join_on_shutdown
(
self
):
def
test_1_join_on_shutdown
(
self
):
# The usual case: on exit, wait for a non-daemon thread
# The usual case: on exit, wait for a non-daemon thread
...
@@ -510,11 +484,8 @@ class ThreadJoinOnShutdown(BaseTestCase):
...
@@ -510,11 +484,8 @@ class ThreadJoinOnShutdown(BaseTestCase):
self
.
_run_and_join
(
script
)
self
.
_run_and_join
(
script
)
def
assertScriptHasOutput
(
self
,
script
,
expected_output
):
def
assertScriptHasOutput
(
self
,
script
,
expected_output
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
script
],
rc
,
out
,
err
=
assert_python_ok
(
"-c"
,
script
)
stdout
=
subprocess
.
PIPE
)
data
=
out
.
decode
()
.
replace
(
'
\r
'
,
''
)
stdout
,
stderr
=
p
.
communicate
()
data
=
stdout
.
decode
()
.
replace
(
'
\r
'
,
''
)
self
.
assertEqual
(
p
.
returncode
,
0
,
"Unexpected error"
)
self
.
assertEqual
(
data
,
expected_output
)
self
.
assertEqual
(
data
,
expected_output
)
@unittest.skipUnless
(
hasattr
(
os
,
'fork'
),
"needs os.fork()"
)
@unittest.skipUnless
(
hasattr
(
os
,
'fork'
),
"needs os.fork()"
)
...
...
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