diff --git a/esphomeyaml/api/client.py b/esphomeyaml/api/client.py index 2708933fd2..da5b71b219 100644 --- a/esphomeyaml/api/client.py +++ b/esphomeyaml/api/client.py @@ -346,6 +346,8 @@ class APIClient(threading.Thread): raise APIConnectionError("No socket!") try: val = self._socket.recv(amount - len(ret)) + except AttributeError: + raise APIConnectionError("Socket was closed") except socket.timeout: continue except socket.error as err: @@ -453,8 +455,8 @@ def run_logs(config, address): time_ = datetime.now().time().strftime(u'[%H:%M:%S]') text = msg.message if msg.send_failed: - text = color('white', '(Message not received because it was too big to fit in ' - 'TCP buffer)') + text = color('white', '(Message skipped because it was too big to fit in ' + 'TCP buffer - This is only cosmetic)') safe_print(time_ + text) has_connects = [] diff --git a/esphomeyaml/util.py b/esphomeyaml/util.py index 0a3a6046d5..eebb4b7c93 100644 --- a/esphomeyaml/util.py +++ b/esphomeyaml/util.py @@ -88,12 +88,14 @@ def run_external_command(func, *cmd, **kwargs): full_cmd = u' '.join(shlex_quote(x) for x in cmd) _LOGGER.info(u"Running: %s", full_cmd) + orig_stdout = sys.stdout sys.stdout = RedirectText(sys.stdout) + orig_stderr = sys.stderr sys.stderr = RedirectText(sys.stderr) capture_stdout = kwargs.get('capture_stdout', False) if capture_stdout: - sys.stdout = io.BytesIO() + cap_stdout = sys.stdout = io.BytesIO() try: sys.argv = list(cmd) @@ -110,13 +112,9 @@ def run_external_command(func, *cmd, **kwargs): sys.argv = orig_argv sys.exit = orig_exit - if isinstance(sys.stdout, RedirectText): - sys.stdout = sys.__stdout__ - if isinstance(sys.stderr, RedirectText): - sys.stderr = sys.__stderr__ + sys.stdout = orig_stdout + sys.stderr = orig_stderr if capture_stdout: # pylint: disable=lost-exception - stdout = sys.stdout.getvalue() - sys.stdout = sys.__stdout__ - return stdout + return cap_stdout.getvalue()