THRIFT-2900 Python THttpClient does not reset socket timeout on exception
Client: Python
Patch: Aiden Scandella <aiden@uber.com>
This closes #322
Wrap THttpClient withTimeout in a try/finally
Otherwise the original value of the socket timeout is not restored properly.
diff --git a/lib/py/src/transport/THttpClient.py b/lib/py/src/transport/THttpClient.py
index ea80a1a..5851fa2 100644
--- a/lib/py/src/transport/THttpClient.py
+++ b/lib/py/src/transport/THttpClient.py
@@ -103,8 +103,10 @@
def _f(*args, **kwargs):
orig_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(args[0].__timeout)
- result = f(*args, **kwargs)
- socket.setdefaulttimeout(orig_timeout)
+ try:
+ result = f(*args, **kwargs)
+ finally:
+ socket.setdefaulttimeout(orig_timeout)
return result
return _f