mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 18:17:13 +02:00
Ensure buffer is created for thread stream
This commit is contained in:
@ -38,14 +38,16 @@ class MultiThreadingStdStream(object):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
thread_id = thread_get_ident()
|
thread_id = thread_get_ident()
|
||||||
if thread_id not in self._buffers:
|
self._ensure_thread_buffer(thread_id)
|
||||||
raise AttributeError(name)
|
|
||||||
return getattr(self._buffers[thread_id], name)
|
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):
|
def write(self, value):
|
||||||
thread_id = thread_get_ident()
|
thread_id = thread_get_ident()
|
||||||
if thread_id not in self._buffers:
|
self._ensure_thread_buffer(thread_id)
|
||||||
self._buffers[thread_id] = BytesIO() if PY2 else StringIO()
|
|
||||||
return self._buffers[thread_id].write(
|
return self._buffers[thread_id].write(
|
||||||
value.decode() if is_bytes(value) else value)
|
value.decode() if is_bytes(value) else value)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user