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
1fc3ec91
Kaydet (Commit)
1fc3ec91
authored
Nis 29, 2012
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #14428: Rewrite test_process_time_threads() test
time.process_time() is CPU time, not a number of seconds.
üst
b63fd2a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
7 deletions
+40
-7
test_time.py
Lib/test/test_time.py
+40
-7
No files found.
Lib/test/test_time.py
Dosyayı görüntüle @
1fc3ec91
...
...
@@ -392,20 +392,53 @@ class TimeTestCase(unittest.TestCase):
@unittest.skipUnless
(
threading
,
'need threading'
)
def
test_process_time_threads
(
self
):
class
BusyThread
(
threading
.
Thread
):
def
factorial
(
n
):
if
n
>=
2
:
return
n
*
factorial
(
n
-
1
)
else
:
return
1
def
use_cpu
(
n
,
loops
):
for
loop
in
range
(
loops
):
factorial
(
n
)
class
FactorialThread
(
threading
.
Thread
):
def
__init__
(
self
,
n
,
loops
):
threading
.
Thread
.
__init__
(
self
)
self
.
n
=
n
self
.
loops
=
loops
def
run
(
self
):
while
not
self
.
stop
:
pass
use_cpu
(
self
.
n
,
self
.
loops
)
# Calibrate use_cpu() to use at least 1 ms of system time
n
=
50
loops
=
1
resolution
=
time
.
get_clock_info
(
'process_time'
)
.
resolution
min_rdt
=
max
(
resolution
,
0.001
)
while
1
:
rt1
=
time
.
time
()
t1
=
time
.
process_time
()
use_cpu
(
n
,
loops
)
t2
=
time
.
process_time
()
rt2
=
time
.
time
()
rdt
=
rt2
-
rt1
if
rdt
>=
min_rdt
:
break
loops
*=
2
busy
=
t2
-
t1
thread
=
BusyThread
()
thread
.
stop
=
False
# Ensure that time.process_time() includes the CPU time of all threads
thread
=
FactorialThread
(
n
,
loops
)
t1
=
time
.
process_time
()
thread
.
start
()
time
.
sleep
(
0.2
)
# Use sleep() instead of thread.join() because thread.join() time may
# be included in time.process_time() depending on its implementation
time
.
sleep
(
rdt
*
2
)
t2
=
time
.
process_time
()
thread
.
stop
=
True
thread
.
join
()
self
.
assertGreater
(
t2
-
t1
,
0.1
)
self
.
assertGreater
Equal
(
t2
-
t1
,
busy
)
@unittest.skipUnless
(
hasattr
(
time
,
'monotonic'
),
'need time.monotonic'
)
...
...
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