Skip to content

Commit ebca392

Browse files
committed
(Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when
available to compute timeout.
2 parents 0ddaed3 + 2ff68dd commit ebca392

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Lib/telnetlib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
import sys
3737
import socket
3838
import 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

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #19339: telnetlib module is now using time.monotonic() when available
31+
to compute timeout.
32+
3033
- Issue #19399: fix sporadic test_subprocess failure.
3134

3235
- Issue #13234: Fix os.listdir to work with extended paths on Windows.

0 commit comments

Comments
 (0)