36
36
import sys
37
37
import socket
38
38
import selectors
39
+ try :
40
+ from time import monotonic as _time
41
+ except ImportError :
42
+ from time import time as _time
39
43
40
44
__all__ = ["Telnet" ]
41
45
@@ -304,8 +308,7 @@ def read_until(self, match, timeout=None):
304
308
self .cookedq = self .cookedq [i :]
305
309
return buf
306
310
if timeout is not None :
307
- from time import time
308
- deadline = time () + timeout
311
+ deadline = _time () + timeout
309
312
with _TelnetSelector () as selector :
310
313
selector .register (self , selectors .EVENT_READ )
311
314
while not self .eof :
@@ -320,7 +323,7 @@ def read_until(self, match, timeout=None):
320
323
self .cookedq = self .cookedq [i :]
321
324
return buf
322
325
if timeout is not None :
323
- timeout = deadline - time ()
326
+ timeout = deadline - _time ()
324
327
if timeout < 0 :
325
328
break
326
329
return self .read_very_lazy ()
@@ -610,8 +613,7 @@ def expect(self, list, timeout=None):
610
613
if not re : import re
611
614
list [i ] = re .compile (list [i ])
612
615
if timeout is not None :
613
- from time import time
614
- deadline = time () + timeout
616
+ deadline = _time () + timeout
615
617
with _TelnetSelector () as selector :
616
618
selector .register (self , selectors .EVENT_READ )
617
619
while not self .eof :
@@ -625,7 +627,7 @@ def expect(self, list, timeout=None):
625
627
return (i , m , text )
626
628
if timeout is not None :
627
629
ready = selector .select (timeout )
628
- timeout = deadline - time ()
630
+ timeout = deadline - _time ()
629
631
if not ready :
630
632
if timeout < 0 :
631
633
break
0 commit comments