3636import sys
3737import socket
3838import selectors
39+ try :
40+ from time import monotonic as _time
41+ except ImportError :
42+ from time import time as _time
3943
4044__all__ = ["Telnet" ]
4145
@@ -304,8 +308,7 @@ def read_until(self, match, timeout=None):
304308 self .cookedq = self .cookedq [i :]
305309 return buf
306310 if timeout is not None :
307- from time import time
308- deadline = time () + timeout
311+ deadline = _time () + timeout
309312 with _TelnetSelector () as selector :
310313 selector .register (self , selectors .EVENT_READ )
311314 while not self .eof :
@@ -320,7 +323,7 @@ def read_until(self, match, timeout=None):
320323 self .cookedq = self .cookedq [i :]
321324 return buf
322325 if timeout is not None :
323- timeout = deadline - time ()
326+ timeout = deadline - _time ()
324327 if timeout < 0 :
325328 break
326329 return self .read_very_lazy ()
@@ -610,8 +613,7 @@ def expect(self, list, timeout=None):
610613 if not re : import re
611614 list [i ] = re .compile (list [i ])
612615 if timeout is not None :
613- from time import time
614- deadline = time () + timeout
616+ deadline = _time () + timeout
615617 with _TelnetSelector () as selector :
616618 selector .register (self , selectors .EVENT_READ )
617619 while not self .eof :
@@ -625,7 +627,7 @@ def expect(self, list, timeout=None):
625627 return (i , m , text )
626628 if timeout is not None :
627629 ready = selector .select (timeout )
628- timeout = deadline - time ()
630+ timeout = deadline - _time ()
629631 if not ready :
630632 if timeout < 0 :
631633 break
0 commit comments