From 32cb0d6e4deec18dc650afcf08bd5988eb8069e9 Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Fri, 22 May 2020 14:17:17 +0300 Subject: [PATCH] Handle possible issue on Python 2.x when writing to thread buffer The problem happens when value has type "unicode" that shouldn't be decoded --- platformio/commands/home/rpc/handlers/piocore.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platformio/commands/home/rpc/handlers/piocore.py b/platformio/commands/home/rpc/handlers/piocore.py index 44cb6983..940b1dd2 100644 --- a/platformio/commands/home/rpc/handlers/piocore.py +++ b/platformio/commands/home/rpc/handlers/piocore.py @@ -51,8 +51,10 @@ class MultiThreadingStdStream(object): def write(self, value): thread_id = thread_get_ident() self._ensure_thread_buffer(thread_id) + if PY2 and isinstance(value, unicode): + value = value.encode() return self._buffers[thread_id].write( - value.decode() if not PY2 and is_bytes(value) else value + value.decode() if is_bytes(value) else value ) def get_value_and_reset(self):