From f30a4c552e236b195b539392b4c526ec1ff73c10 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Wed, 30 Aug 2017 19:47:54 -0400 Subject: [PATCH] Better way to shutdown the socket under python3 Fixes the test_sequential_watch_prefix_once functional test under python 3.x --- etcd3gw/watch.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/etcd3gw/watch.py b/etcd3gw/watch.py index d639de1..2a2cfd7 100644 --- a/etcd3gw/watch.py +++ b/etcd3gw/watch.py @@ -11,6 +11,8 @@ # under the License. import json +import six +import socket from etcd3gw.utils import _decode from etcd3gw.utils import _encode @@ -63,7 +65,14 @@ def __init__(self, client, key, callback, **kwargs): def stop(self): try: - self._response.raw._fp.close() + 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() except Exception: pass self._response.connection.close()