classification
Title: TimeoutError isn't being raised?
Type: behavior Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: YoSTEALTH
Priority: normal Keywords:

Created on 2017-01-06 22:55 by YoSTEALTH, last changed 2017-01-07 07:25 by xiang.zhang. This issue is now closed.

Messages (1)
msg284868 - (view) Author: (YoSTEALTH) * Date: 2017-01-06 22:55
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?
History
Date User Action Args
2017-01-07 07:25:53xiang.zhangsetstage: resolved
2017-01-07 00:06:57YoSTEALTHsetstatus: open -> closed
resolution: not a bug
2017-01-06 22:55:58YoSTEALTHcreate