Kaydet (Commit) ebca392a authored tarafından Victor Stinner's avatar Victor Stinner

(Merge 3.3) Close #19339: telnetlib module is now using time.monotonic() when

available to compute timeout.
...@@ -36,6 +36,10 @@ To do: ...@@ -36,6 +36,10 @@ To do:
import sys import sys
import socket import socket
import selectors import selectors
try:
from time import monotonic as _time
except ImportError:
from time import time as _time
__all__ = ["Telnet"] __all__ = ["Telnet"]
...@@ -304,8 +308,7 @@ class Telnet: ...@@ -304,8 +308,7 @@ class Telnet:
self.cookedq = self.cookedq[i:] self.cookedq = self.cookedq[i:]
return buf return buf
if timeout is not None: if timeout is not None:
from time import time deadline = _time() + timeout
deadline = time() + timeout
with _TelnetSelector() as selector: with _TelnetSelector() as selector:
selector.register(self, selectors.EVENT_READ) selector.register(self, selectors.EVENT_READ)
while not self.eof: while not self.eof:
...@@ -320,7 +323,7 @@ class Telnet: ...@@ -320,7 +323,7 @@ class Telnet:
self.cookedq = self.cookedq[i:] self.cookedq = self.cookedq[i:]
return buf return buf
if timeout is not None: if timeout is not None:
timeout = deadline - time() timeout = deadline - _time()
if timeout < 0: if timeout < 0:
break break
return self.read_very_lazy() return self.read_very_lazy()
...@@ -610,8 +613,7 @@ class Telnet: ...@@ -610,8 +613,7 @@ class Telnet:
if not re: import re if not re: import re
list[i] = re.compile(list[i]) list[i] = re.compile(list[i])
if timeout is not None: if timeout is not None:
from time import time deadline = _time() + timeout
deadline = time() + timeout
with _TelnetSelector() as selector: with _TelnetSelector() as selector:
selector.register(self, selectors.EVENT_READ) selector.register(self, selectors.EVENT_READ)
while not self.eof: while not self.eof:
...@@ -625,7 +627,7 @@ class Telnet: ...@@ -625,7 +627,7 @@ class Telnet:
return (i, m, text) return (i, m, text)
if timeout is not None: if timeout is not None:
ready = selector.select(timeout) ready = selector.select(timeout)
timeout = deadline - time() timeout = deadline - _time()
if not ready: if not ready:
if timeout < 0: if timeout < 0:
break break
......
...@@ -27,6 +27,9 @@ Core and Builtins ...@@ -27,6 +27,9 @@ Core and Builtins
Library Library
------- -------
- Issue #19339: telnetlib module is now using time.monotonic() when available
to compute timeout.
- Issue #19399: fix sporadic test_subprocess failure. - Issue #19399: fix sporadic test_subprocess failure.
- Issue #13234: Fix os.listdir to work with extended paths on Windows. - Issue #13234: Fix os.listdir to work with extended paths on Windows.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment