Internal Design#
pw_console: Multi-purpose pluggable interactive console for dev & manufacturing
Threads and Event Loops#
In ptpython and IPython all user repl code is run in the foreground. This
allows interrupts like Ctrl-C
and functions like print()
and
time.sleep()
to work as expected. Pigweed’s Console doesn’t use this
approach as it would hide or freeze the prompt_toolkit user interface while
running repl code.
To get around this issue all user repl code is run in a dedicated thread with stdout and stderr patched to capture output. This lets the user interface stay responsive and new log messages to continue to be displayed.
Here’s a diagram showing how pw_console
threads and asyncio tasks are
organized.