@@ -46,12 +46,12 @@ def __enter__(self) -> Self:
4646 self .previous_handler = signal .signal (signal .SIGALRM , self .raise_timeout ) # type: ignore[assignment]
4747 self .previous_timer = signal .alarm (self .timeout )
4848
49- self .start_time = time .time ()
49+ self .start_time = time .monotonic ()
5050 return self
5151
5252 def __exit__ (self , exc_type : type [BaseException ] | None , exc_value : BaseException | None , traceback : TracebackType | None ) -> None :
5353 if self .start_time :
54- time_delta = time .time () - self .start_time
54+ time_delta = time .monotonic () - self .start_time
5555 signal .alarm (0 )
5656 self .time = time_delta
5757 if self .timeout > 0 :
@@ -165,7 +165,7 @@ def build_icmp(payload: bytes) -> bytes:
165165
166166def ping (hostname : str , timeout : int = 5 ) -> int :
167167 watchdog = select .epoll ()
168- started = time .time ()
168+ started = time .monotonic ()
169169 random_identifier = f'archinstall-{ random .randint (1000 , 9999 )} ' .encode ()
170170
171171 # Create a raw socket (requires root, which should be fine on archiso)
@@ -180,15 +180,15 @@ def ping(hostname: str, timeout: int = 5) -> int:
180180
181181 # Gracefully wait for X amount of time
182182 # for a ICMP response or exit with no latency
183- while latency == - 1 and time .time () - started < timeout :
183+ while latency == - 1 and time .monotonic () - started < timeout :
184184 try :
185185 for _fileno , _event in watchdog .poll (0.1 ):
186186 response , _ = icmp_socket .recvfrom (1024 )
187187 icmp_type = struct .unpack ('!B' , response [20 :21 ])[0 ]
188188
189189 # Check if it's an Echo Reply (ICMP type 0)
190190 if icmp_type == 0 and response [- len (random_identifier ) :] == random_identifier :
191- latency = round ((time .time () - started ) * 1000 )
191+ latency = round ((time .monotonic () - started ) * 1000 )
192192 break
193193 except OSError as e :
194194 debug (f'Error: { e } ' )
0 commit comments