TimeoutError isn't being raised?
My Python Version: 3.5.1 (64bit, linux)
# Document:
https://docs.python.org/3/library/exceptions.html#TimeoutError
""" exception TimeoutError
Raised when a system function timed out at the system level. Corresponds to errno ETIMEDOUT.
New in version 3.3: All the above OSError subclasses were added.
See also PEP 3151 - Reworking the OS and IO exception hierarchy """
# PEP: According to pep-3151
link: https://www.python.org/dev/peps/pep-3151/
""" TimeoutError : connection timed out (ETIMEDOUT); this can be re-cast as a generic timeout exception, replacing socket.timeout and also useful for other types of timeout (for example in Lock.acquire()) """
# This Does NOT Work:
def Send(conn, data):
# Set Timeout.
conn.settimeout(3.0)
try:
while data:
sent = conn.send(data)
data = data[sent:]
except TimeoutError as e:
print("TimeoutError:", e) #
close_connection()
else:
pass # Do Stuff...
# This Works
def Send(conn, data):
# Set Timeout.
conn.settimeout(3.0)
try:
while data:
sent = conn.send(data)
data = data[sent:]
except socket.timeout as e:
print("socket.timeout:", e) # socket.timeout: timed out
close_connection()
else:
pass # Do Stuff...
# This Works
def Send(conn, data):
# Set Timeout.
conn.settimeout(3.0)
try:
while data:
sent = conn.send(data)
data = data[sent:]
except OSError as e:
print('ERROR Send:', e) # ERROR Send: timed out
close_connection()
else:
pass # Do Stuff...
According to PEP "TimeoutError" is suppose to replace "socket.timeout" but it doesn't seem to work! Any ideas why?
|