summaryrefslogtreecommitdiffstatshomepage
path: root/tools/pyboard.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-04-25 13:24:32 +1000
committerDamien George <damien.p.george@gmail.com>2019-04-25 13:24:32 +1000
commit56f6ceba7f6e86a47680660dbfe81a0a64682eaf (patch)
treeb4848f15137e60f6b116449384cd178eaebd6745 /tools/pyboard.py
parentaa7b32c81136b1250d9515adf9d13eefd81e86d4 (diff)
downloadmicropython-56f6ceba7f6e86a47680660dbfe81a0a64682eaf.tar.gz
micropython-56f6ceba7f6e86a47680660dbfe81a0a64682eaf.zip
tools/pyboard.py: Don't accumulate output data if data_consumer used.
Prior to this patch, when a lot of data was output by a running script pyboard.py would try to capture all of this output into the "data" variable, which would gradually slow down pyboard.py to the point where it would have large CPU and memory usage (on the host) and potentially lose data. This patch fixes this problem by not accumulating the data in the case that the data is not needed, which is when "data_consumer" is used.
Diffstat (limited to 'tools/pyboard.py')
-rwxr-xr-xtools/pyboard.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/pyboard.py b/tools/pyboard.py
index 42b077de22..d906235066 100755
--- a/tools/pyboard.py
+++ b/tools/pyboard.py
@@ -261,6 +261,9 @@ class Pyboard:
self.serial.close()
def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
+ # if data_consumer is used then data is not accumulated and the ending must be 1 byte long
+ assert data_consumer is None or len(ending) == 1
+
data = self.serial.read(min_num_bytes)
if data_consumer:
data_consumer(data)
@@ -270,9 +273,11 @@ class Pyboard:
break
elif self.serial.inWaiting() > 0:
new_data = self.serial.read(1)
- data = data + new_data
if data_consumer:
data_consumer(new_data)
+ data = new_data
+ else:
+ data = data + new_data
timeout_count = 0
else:
timeout_count += 1