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
aebac0b5
Kaydet (Commit)
aebac0b5
authored
Mar 24, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add tests for the atexit hook in concurrent.futures (part of #11635)
üst
2024acd3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
15 deletions
+40
-15
test_concurrent_futures.py
Lib/test/test_concurrent_futures.py
+40
-15
No files found.
Lib/test/test_concurrent_futures.py
Dosyayı görüntüle @
aebac0b5
...
...
@@ -9,6 +9,9 @@ test.support.import_module('multiprocessing.synchronize')
# without thread support.
test
.
support
.
import_module
(
'threading'
)
from
test.script_helper
import
assert_python_ok
import
sys
import
threading
import
time
import
unittest
...
...
@@ -43,9 +46,30 @@ def sleep_and_raise(t):
time
.
sleep
(
t
)
raise
Exception
(
'this is an exception'
)
def
sleep_and_print
(
t
,
msg
):
time
.
sleep
(
t
)
print
(
msg
)
sys
.
stdout
.
flush
()
class
ExecutorMixin
:
worker_count
=
5
def
setUp
(
self
):
self
.
t1
=
time
.
time
()
try
:
self
.
executor
=
self
.
executor_type
(
max_workers
=
self
.
worker_count
)
except
NotImplementedError
as
e
:
self
.
skipTest
(
str
(
e
))
self
.
_prime_executor
()
def
tearDown
(
self
):
self
.
executor
.
shutdown
(
wait
=
True
)
dt
=
time
.
time
()
-
self
.
t1
if
test
.
support
.
verbose
:
print
(
"
%.2
fs"
%
dt
,
end
=
' '
)
self
.
assertLess
(
dt
,
60
,
"synchronization issue: test lasted too long"
)
def
_prime_executor
(
self
):
# Make sure that the executor is ready to do work before running the
# tests. This should reduce the probability of timeouts in the tests.
...
...
@@ -57,24 +81,11 @@ class ExecutorMixin:
class
ThreadPoolMixin
(
ExecutorMixin
):
def
setUp
(
self
):
self
.
executor
=
futures
.
ThreadPoolExecutor
(
max_workers
=
5
)
self
.
_prime_executor
()
def
tearDown
(
self
):
self
.
executor
.
shutdown
(
wait
=
True
)
executor_type
=
futures
.
ThreadPoolExecutor
class
ProcessPoolMixin
(
ExecutorMixin
):
def
setUp
(
self
):
try
:
self
.
executor
=
futures
.
ProcessPoolExecutor
(
max_workers
=
5
)
except
NotImplementedError
as
e
:
self
.
skipTest
(
str
(
e
))
self
.
_prime_executor
()
def
tearDown
(
self
):
self
.
executor
.
shutdown
(
wait
=
True
)
executor_type
=
futures
.
ProcessPoolExecutor
class
ExecutorShutdownTest
(
unittest
.
TestCase
):
...
...
@@ -84,6 +95,20 @@ class ExecutorShutdownTest(unittest.TestCase):
self
.
executor
.
submit
,
pow
,
2
,
5
)
def
test_interpreter_shutdown
(
self
):
# Test the atexit hook for shutdown of worker threads and processes
rc
,
out
,
err
=
assert_python_ok
(
'-c'
,
"""if 1:
from concurrent.futures import {executor_type}
from time import sleep
from test.test_concurrent_futures import sleep_and_print
t = {executor_type}(5)
t.submit(sleep_and_print, 1.0, "apple")
"""
.
format
(
executor_type
=
self
.
executor_type
.
__name__
))
# Errors in atexit hooks don't change the process exit code, check
# stderr manually.
self
.
assertFalse
(
err
)
self
.
assertEqual
(
out
.
strip
(),
b
"apple"
)
class
ThreadPoolShutdownTest
(
ThreadPoolMixin
,
ExecutorShutdownTest
):
def
_prime_executor
(
self
):
...
...
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