[issue32729] socket error handling needed

yang report at bugs.python.org
Sat Feb 3 05:54:37 EST 2018


yang <rkdls9 at naver.com> added the comment:

Oh.. you are right. 
I think it's my bug. here is code
```
import urllib3
import certifi
from functools import wraps
import signal
from urllib3 import Timeout


def timeoutdec(sec):
    def decorator(func):
        def _timeout(signum, frame):
            raise TimeoutError()

        @wraps(func)
        def wrapper(*args, **kwargs):
            signal.signal(signal.SIGALRM, _timeout)
            signal.alarm(sec)
            try:
                result = func(*args, **kwargs)
            finally:
                signal.alarm(0)
            return result
        return wrapper
    return decorator


@timeoutdec(2)
def for_test():
    timeout = Timeout(connect=10.0, read=2.0)
    url = 'http://httpbin.org/delay/7'
    method = 'GET'
    body = None
    headers = None
    http = urllib3.PoolManager(timeout=timeout,
                               cert_reqs='CERT_REQUIRED',
                               ca_certs=certifi.where())
    while True:
        response = http.urlopen(method, url,
                                body=body,
                                headers=headers,
                                preload_content=True)

        print(response.data)


for_test()

```

here is the code that i got same traceback.

maybe the TimeoutError is raised from my code, timeoutdec().

I thought it was python bug. sorry for bothering you.


and I will close my PR-32729.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32729>
_______________________________________


More information about the Python-bugs-list mailing list