@@ -157,11 +157,11 @@ def __init__(self, func):
157157 self .elapsed = None
158158
159159 def __call__ (self , * args , ** kwds ):
160- t = time .time ()
160+ t = time .monotonic ()
161161 try :
162162 return self .func (* args , ** kwds )
163163 finally :
164- self .elapsed = time .time () - t
164+ self .elapsed = time .monotonic () - t
165165
166166#
167167# Base class for test cases
@@ -1036,9 +1036,9 @@ def test_no_import_lock_contention(self):
10361036
10371037 def test_timeout (self ):
10381038 q = multiprocessing .Queue ()
1039- start = time .time ()
1039+ start = time .monotonic ()
10401040 self .assertRaises (pyqueue .Empty , q .get , True , 0.200 )
1041- delta = time .time () - start
1041+ delta = time .monotonic () - start
10421042 # bpo-30317: Tolerate a delta of 100 ms because of the bad clock
10431043 # resolution on Windows (usually 15.6 ms). x86 Windows7 3.x once
10441044 # failed because the delta was only 135.8 ms.
@@ -1434,9 +1434,9 @@ def _test_waitfor_timeout_f(cls, cond, state, success, sem):
14341434 sem .release ()
14351435 with cond :
14361436 expected = 0.1
1437- dt = time .time ()
1437+ dt = time .monotonic ()
14381438 result = cond .wait_for (lambda : state .value == 4 , timeout = expected )
1439- dt = time .time () - dt
1439+ dt = time .monotonic () - dt
14401440 # borrow logic in assertTimeout() from test/lock_tests.py
14411441 if not result and expected * 0.6 < dt < expected * 10.0 :
14421442 success .value = True
@@ -2527,7 +2527,7 @@ def test_map_no_failfast(self):
25272527 # process would fill the result queue (after the result handler thread
25282528 # terminated, hence not draining it anymore).
25292529
2530- t_start = time .time ()
2530+ t_start = time .monotonic ()
25312531
25322532 with self .assertRaises (ValueError ):
25332533 with self .Pool (2 ) as p :
@@ -2539,7 +2539,7 @@ def test_map_no_failfast(self):
25392539 p .join ()
25402540
25412541 # check that we indeed waited for all jobs
2542- self .assertGreater (time .time () - t_start , 0.9 )
2542+ self .assertGreater (time .monotonic () - t_start , 0.9 )
25432543
25442544 def test_release_task_refs (self ):
25452545 # Issue #29861: task arguments and results should not be kept
@@ -4051,19 +4051,19 @@ def test_wait_timeout(self):
40514051 expected = 5
40524052 a , b = multiprocessing .Pipe ()
40534053
4054- start = time .time ()
4054+ start = time .monotonic ()
40554055 res = wait ([a , b ], expected )
4056- delta = time .time () - start
4056+ delta = time .monotonic () - start
40574057
40584058 self .assertEqual (res , [])
40594059 self .assertLess (delta , expected * 2 )
40604060 self .assertGreater (delta , expected * 0.5 )
40614061
40624062 b .send (None )
40634063
4064- start = time .time ()
4064+ start = time .monotonic ()
40654065 res = wait ([a , b ], 20 )
4066- delta = time .time () - start
4066+ delta = time .monotonic () - start
40674067
40684068 self .assertEqual (res , [a ])
40694069 self .assertLess (delta , 0.4 )
@@ -4087,28 +4087,28 @@ def test_wait_integer(self):
40874087 self .assertIsInstance (p .sentinel , int )
40884088 self .assertTrue (sem .acquire (timeout = 20 ))
40894089
4090- start = time .time ()
4090+ start = time .monotonic ()
40914091 res = wait ([a , p .sentinel , b ], expected + 20 )
4092- delta = time .time () - start
4092+ delta = time .monotonic () - start
40934093
40944094 self .assertEqual (res , [p .sentinel ])
40954095 self .assertLess (delta , expected + 2 )
40964096 self .assertGreater (delta , expected - 2 )
40974097
40984098 a .send (None )
40994099
4100- start = time .time ()
4100+ start = time .monotonic ()
41014101 res = wait ([a , p .sentinel , b ], 20 )
4102- delta = time .time () - start
4102+ delta = time .monotonic () - start
41034103
41044104 self .assertEqual (sorted_ (res ), sorted_ ([p .sentinel , b ]))
41054105 self .assertLess (delta , 0.4 )
41064106
41074107 b .send (None )
41084108
4109- start = time .time ()
4109+ start = time .monotonic ()
41104110 res = wait ([a , p .sentinel , b ], 20 )
4111- delta = time .time () - start
4111+ delta = time .monotonic () - start
41124112
41134113 self .assertEqual (sorted_ (res ), sorted_ ([a , p .sentinel , b ]))
41144114 self .assertLess (delta , 0.4 )
@@ -4119,9 +4119,9 @@ def test_wait_integer(self):
41194119 def test_neg_timeout (self ):
41204120 from multiprocessing .connection import wait
41214121 a , b = multiprocessing .Pipe ()
4122- t = time .time ()
4122+ t = time .monotonic ()
41234123 res = wait ([a ], timeout = - 1 )
4124- t = time .time () - t
4124+ t = time .monotonic () - t
41254125 self .assertEqual (res , [])
41264126 self .assertLess (t , 1 )
41274127 a .close ()
0 commit comments