Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Commit

Permalink
Use the socket shutdown() workaround on Python 2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fasaxc authored and dims committed Apr 4, 2018
1 parent 309df0c commit 797cb2e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions etcd3gw/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# under the License.

import json
import six
import socket

from etcd3gw.utils import _decode
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 797cb2e

Please sign in to comment.