From fd9ca0cd15e86fc44bd564db65333e667fb44585 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 2 Jul 2019 22:35:35 +0300 Subject: [PATCH] Ensure buffer is created for thread stream --- platformio/commands/home/rpc/handlers/piocore.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platformio/commands/home/rpc/handlers/piocore.py b/platformio/commands/home/rpc/handlers/piocore.py index d22a6e80..ef290ea3 100644 --- a/platformio/commands/home/rpc/handlers/piocore.py +++ b/platformio/commands/home/rpc/handlers/piocore.py @@ -38,14 +38,16 @@ class MultiThreadingStdStream(object): def __getattr__(self, name): thread_id = thread_get_ident() - if thread_id not in self._buffers: - raise AttributeError(name) + self._ensure_thread_buffer(thread_id) return getattr(self._buffers[thread_id], name) + def _ensure_thread_buffer(self, thread_id): + if thread_id not in self._buffers: + self._buffers[thread_id] = BytesIO() if PY2 else StringIO() + def write(self, value): thread_id = thread_get_ident() - if thread_id not in self._buffers: - self._buffers[thread_id] = BytesIO() if PY2 else StringIO() + self._ensure_thread_buffer(thread_id) return self._buffers[thread_id].write( value.decode() if is_bytes(value) else value)