Skip to content

Commit

Permalink
Merge branch 'fix/linux_target_interactive' into 'master'
Browse files Browse the repository at this point in the history
fix: unbuffered read for linux target

Closes IDF-8729

See merge request espressif/esp-idf-monitor!47
  • Loading branch information
dobairoland committed Dec 1, 2023
2 parents 73e61e4 + ff1cca8 commit 8529070
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions esp_idf_monitor/base/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def get_parser(): # type: () -> argparse.ArgumentParser
'--eol',
choices=['CR', 'LF', 'CRLF'],
type=lambda c: c.upper(),
help='End of line to use when sending to the serial port',
default='CR')
help='End of line to use when sending to the serial port. '
'Defaults to LF for Linux targets and CR otherwise.',
)

parser.add_argument(
'elf_file', help='ELF file of application',
Expand Down
8 changes: 3 additions & 5 deletions esp_idf_monitor/base/serial_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,12 @@ def __init__(self, process, event_queue):
self.proc = process
self.event_queue = event_queue

self._stdout = iter(self.proc.stdout.readline, b'') # type: ignore

def run(self): # type: () -> None
try:
while self.alive:
for line in self._stdout:
if line:
self.event_queue.put((TAG_SERIAL, line), False)
c = self.proc.stdout.read(1) # type: ignore
if c:
self.event_queue.put((TAG_SERIAL, c), False)
finally:
self.proc.terminate()

Expand Down
5 changes: 4 additions & 1 deletion esp_idf_monitor/idf_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
else:
socket_test_mode = False
self.serial = subprocess.Popen([self.elf_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT, bufsize=0)
self.serial_reader = LinuxReader(self.serial, self.event_queue)

self.gdb_helper = None
Expand Down Expand Up @@ -332,6 +332,9 @@ def main() -> None:
parser = get_parser()
args = parser.parse_args()

# use EOL from argument; defaults to LF for Linux targets and CR otherwise
args.eol = args.eol or ('LF' if args.target == 'linux' else 'CR')

if isinstance(args.elf_file, io.BufferedReader):
elf_file = args.elf_file.name
args.elf_file.close() # don't need this as a file
Expand Down

0 comments on commit 8529070

Please sign in to comment.