Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add close method to websocket client #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# v1.0.1
- Bugfix: blocking exec call should remove channel metadata #140
- Add close method to websocket api of interactive exec #145

# v1.0.0b3
- Bugfix: Missing websocket-client dependency #131
Expand Down
1 change: 1 addition & 0 deletions examples/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@
resp.write_stdin("whoami\n")
user = resp.readline_stdout(timeout=3)
print("Server user is: %s" % user)
resp.close()
8 changes: 8 additions & 0 deletions kubernetes/client/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ def run_forever(self, timeout=None):
while self.is_open():
self.update(timeout=None)

def close(self, **kwargs):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are some of the variable arguments you envision being used here? Just trying to get a feel for this change...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just out of curiosity, should we return True/False if we were able to close successfully the socket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at WebScoket close method for more information: https://github.com/websocket-client/websocket-client/blob/master/websocket/_core.py#L372
that method does not return any status.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

"""
close websocket connection.
"""
self._connected = False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that the socket is open before closing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close method is safe to call even if the socket is closed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

if self.sock:
self.sock.close(**kwargs)


WSResponse = collections.namedtuple('WSResponse', ['data'])

Expand Down