Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 5092d96

Browse files
authored
Merge pull request #160 from oz123/exit_code
Add property returncode to WSClient
2 parents 4c1ab55 + 69570ac commit 5092d96

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

stream/ws_client.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414

1515
from kubernetes.client.rest import ApiException
1616

17-
import select
1817
import certifi
19-
import time
2018
import collections
21-
from websocket import WebSocket, ABNF, enableTrace
22-
import six
19+
import select
2320
import ssl
21+
import time
22+
23+
import six
24+
import yaml
25+
2426
from six.moves.urllib.parse import urlencode, quote_plus, urlparse, urlunparse
2527

28+
from websocket import WebSocket, ABNF, enableTrace
29+
2630
STDIN_CHANNEL = 0
2731
STDOUT_CHANNEL = 1
2832
STDERR_CHANNEL = 2
@@ -203,6 +207,21 @@ def run_forever(self, timeout=None):
203207
else:
204208
while self.is_open():
205209
self.update(timeout=None)
210+
@property
211+
def returncode(self):
212+
"""
213+
The return code, A None value indicates that the process hasn't
214+
terminated yet.
215+
"""
216+
if self.is_open():
217+
return None
218+
else:
219+
err = self.read_channel(ERROR_CHANNEL)
220+
err = yaml.safe_load(err)
221+
if err['status'] == "Success":
222+
return 0
223+
return int(err['details']['causes'][0]['message'])
224+
206225

207226
def close(self, **kwargs):
208227
"""

0 commit comments

Comments
 (0)