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
This commit is contained in:
Shaun Crampton 2018-04-04 14:35:40 +01:00 committed by Davanum Srinivas
parent 309df0ce0e
commit 797cb2e673

View File

@ -11,7 +11,6 @@
# under the License. # under the License.
import json import json
import six
import socket import socket
from etcd3gw.utils import _decode from etcd3gw.utils import _decode
@ -65,14 +64,11 @@ class Watcher(object):
def stop(self): def stop(self):
try: try:
if six.PY2: s = socket.fromfd(self._response.raw._fp.fileno(),
self._response.raw._fp.close() socket.AF_INET,
else: socket.SOCK_STREAM)
s = socket.fromfd(self._response.raw._fp.fileno(), s.shutdown(socket.SHUT_RDWR)
socket.AF_INET, s.close()
socket.SOCK_STREAM)
s.shutdown(socket.SHUT_RDWR)
s.close()
except Exception: except Exception:
pass pass
self._response.connection.close() self._response.connection.close()