Internal Design#
Pigweed AI summary: The Pigweed Console runs user repl code in a dedicated thread with stdout and stderr patched to capture output, allowing the user interface to stay responsive and new log messages to continue to be displayed. This is different from ptpython and IPython, where all user repl code is run in the foreground, which can hide or freeze the prompt_toolkit user interface while running repl code. The diagram shows how Pigweed Console threads and asyncio tasks are organized.
Threads and Event Loops#
Pigweed AI summary: The article discusses how user repl code is run in the foreground in ptpython and IPython, allowing for interrupts and functions to work as expected. However, Pigweed's Console runs user repl code in a dedicated thread with stdout and stderr patched to capture output, in order to keep the user interface responsive. The article includes a diagram showing how pw_console threads and asyncio tasks are organized.
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.