sb/execute: Use a decoder that maintains state aross blocks

Update #4734
This commit is contained in:
Chris Johns 2022-09-29 20:57:56 +10:00
parent 08ca387229
commit ddfcc320ab

View File

@ -27,6 +27,7 @@
from __future__ import print_function from __future__ import print_function
import functools import functools
import codecs
import io import io
import os import os
import re import re
@ -181,6 +182,7 @@ class execute(object):
if trace_threads: if trace_threads:
print('execute:_readthread: start') print('execute:_readthread: start')
decoder = codecs.getincrementaldecoder(sys.stdout.encoding)()
count = 0 count = 0
line = '' line = ''
try: try:
@ -201,7 +203,7 @@ class execute(object):
break break
# str and bytes are the same type in Python2 # str and bytes are the same type in Python2
if type(data) is not str and type(data) is bytes: if type(data) is not str and type(data) is bytes:
data = data.decode(sys.stdout.encoding) data = decoder.decode(data)
last_ch = data[-1] last_ch = data[-1]
sd = (line + data).split('\n') sd = (line + data).split('\n')
if last_ch != '\n': if last_ch != '\n':