From 797cb2e673b9cd08c17ede032af3582b9fbb9dc9 Mon Sep 17 00:00:00 2001 From: Shaun Crampton Date: Wed, 4 Apr 2018 14:35:40 +0100 Subject: [PATCH] Use the socket shutdown() workaround on Python 2 The previous technique used to try to force-close the watch socket didn't work on (at least) Python 2.7.12 but the old Python 3.x workaround seems to work fine on Python 2.7 as well. Use that. Fixes #15 --- etcd3gw/watch.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/etcd3gw/watch.py b/etcd3gw/watch.py index 2a2cfd7..104265f 100644 --- a/etcd3gw/watch.py +++ b/etcd3gw/watch.py @@ -11,7 +11,6 @@ # under the License. import json -import six import socket from etcd3gw.utils import _decode @@ -65,14 +64,11 @@ def __init__(self, client, key, callback, **kwargs): def stop(self): try: - if six.PY2: - self._response.raw._fp.close() - else: - s = socket.fromfd(self._response.raw._fp.fileno(), - socket.AF_INET, - socket.SOCK_STREAM) - s.shutdown(socket.SHUT_RDWR) - s.close() + s = socket.fromfd(self._response.raw._fp.fileno(), + socket.AF_INET, + socket.SOCK_STREAM) + s.shutdown(socket.SHUT_RDWR) + s.close() except Exception: pass self._response.connection.close()