@@ -155,11 +155,11 @@ def __init__(self, func):
155155 self .elapsed = None
156156
157157 def __call__ (self , * args , ** kwds ):
158- t = time .time ()
158+ t = time .monotonic ()
159159 try :
160160 return self .func (* args , ** kwds )
161161 finally :
162- self .elapsed = time .time () - t
162+ self .elapsed = time .monotonic () - t
163163
164164#
165165# Base class for test cases
@@ -1034,9 +1034,9 @@ def test_no_import_lock_contention(self):
10341034
10351035 def test_timeout (self ):
10361036 q = multiprocessing .Queue ()
1037- start = time .time ()
1037+ start = time .monotonic ()
10381038 self .assertRaises (pyqueue .Empty , q .get , True , 0.200 )
1039- delta = time .time () - start
1039+ delta = time .monotonic () - start
10401040 # bpo-30317: Tolerate a delta of 100 ms because of the bad clock
10411041 # resolution on Windows (usually 15.6 ms). x86 Windows7 3.x once
10421042 # failed because the delta was only 135.8 ms.
@@ -1440,9 +1440,9 @@ def _test_waitfor_timeout_f(cls, cond, state, success, sem):
14401440 sem .release ()
14411441 with cond :
14421442 expected = 0.1
1443- dt = time .time ()
1443+ dt = time .monotonic ()
14441444 result = cond .wait_for (lambda : state .value == 4 , timeout = expected )
1445- dt = time .time () - dt
1445+ dt = time .monotonic () - dt
14461446 # borrow logic in assertTimeout() from test/lock_tests.py
14471447 if not result and expected * 0.6 < dt < expected * 10.0 :
14481448 success .value = True
@@ -2533,7 +2533,7 @@ def test_map_no_failfast(self):
25332533 # process would fill the result queue (after the result handler thread
25342534 # terminated, hence not draining it anymore).
25352535
2536- t_start = time .time ()
2536+ t_start = time .monotonic ()
25372537
25382538 with self .assertRaises (ValueError ):
25392539 with self .Pool (2 ) as p :
@@ -2545,7 +2545,7 @@ def test_map_no_failfast(self):
25452545 p .join ()
25462546
25472547 # check that we indeed waited for all jobs
2548- self .assertGreater (time .time () - t_start , 0.9 )
2548+ self .assertGreater (time .monotonic () - t_start , 0.9 )
25492549
25502550 def test_release_task_refs (self ):
25512551 # Issue #29861: task arguments and results should not be kept
@@ -4108,19 +4108,19 @@ def test_wait_timeout(self):
41084108 expected = 5
41094109 a , b = multiprocessing .Pipe ()
41104110
4111- start = time .time ()
4111+ start = time .monotonic ()
41124112 res = wait ([a , b ], expected )
4113- delta = time .time () - start
4113+ delta = time .monotonic () - start
41144114
41154115 self .assertEqual (res , [])
41164116 self .assertLess (delta , expected * 2 )
41174117 self .assertGreater (delta , expected * 0.5 )
41184118
41194119 b .send (None )
41204120
4121- start = time .time ()
4121+ start = time .monotonic ()
41224122 res = wait ([a , b ], 20 )
4123- delta = time .time () - start
4123+ delta = time .monotonic () - start
41244124
41254125 self .assertEqual (res , [a ])
41264126 self .assertLess (delta , 0.4 )
@@ -4144,28 +4144,28 @@ def test_wait_integer(self):
41444144 self .assertIsInstance (p .sentinel , int )
41454145 self .assertTrue (sem .acquire (timeout = 20 ))
41464146
4147- start = time .time ()
4147+ start = time .monotonic ()
41484148 res = wait ([a , p .sentinel , b ], expected + 20 )
4149- delta = time .time () - start
4149+ delta = time .monotonic () - start
41504150
41514151 self .assertEqual (res , [p .sentinel ])
41524152 self .assertLess (delta , expected + 2 )
41534153 self .assertGreater (delta , expected - 2 )
41544154
41554155 a .send (None )
41564156
4157- start = time .time ()
4157+ start = time .monotonic ()
41584158 res = wait ([a , p .sentinel , b ], 20 )
4159- delta = time .time () - start
4159+ delta = time .monotonic () - start
41604160
41614161 self .assertEqual (sorted_ (res ), sorted_ ([p .sentinel , b ]))
41624162 self .assertLess (delta , 0.4 )
41634163
41644164 b .send (None )
41654165
4166- start = time .time ()
4166+ start = time .monotonic ()
41674167 res = wait ([a , p .sentinel , b ], 20 )
4168- delta = time .time () - start
4168+ delta = time .monotonic () - start
41694169
41704170 self .assertEqual (sorted_ (res ), sorted_ ([a , p .sentinel , b ]))
41714171 self .assertLess (delta , 0.4 )
@@ -4176,9 +4176,9 @@ def test_wait_integer(self):
41764176 def test_neg_timeout (self ):
41774177 from multiprocessing .connection import wait
41784178 a , b = multiprocessing .Pipe ()
4179- t = time .time ()
4179+ t = time .monotonic ()
41804180 res = wait ([a ], timeout = - 1 )
4181- t = time .time () - t
4181+ t = time .monotonic () - t
41824182 self .assertEqual (res , [])
41834183 self .assertLess (t , 1 )
41844184 a .close ()
0 commit comments