gui.ui.monitor_memory
- File:
EuljiroBible/gui/ui/monitor_memory.py
- Author:
Benjamin Jaedon Choi - https://github.com/saintbenjamin
- Affiliated Church:
The Eulji-ro Presbyterian Church [대한예수교장로회(통합) 을지로교회]
- Address:
The Eulji-ro Presbyterian Church, 24-10, Eulji-ro 20-gil, Jung-gu, Seoul 04549, South Korea
- Telephone:
+82-2-2266-3070
- E-mail:
euljirochurch [at] G.M.A.I.L. (replace [at] with @ and G.M.A.I.L as you understood.)
- License:
MIT License with Attribution Requirement (see LICENSE file for details); Copyright (c) 2025 The Eulji-ro Presbyterian Church.
Popup window for monitoring the current Python process memory usage.
This module provides a lightweight GUI tool that periodically measures the resident set size (RSS) of the running process, appends the record to a log file, and displays the latest values in real time.
Key behaviors:
Memory is sampled at a user-configurable interval (seconds).
Each sample is appended to
paths.MEMORY_LOG_FILE(typicallymemory_log.txt).Entries exceeding a fixed warning threshold (currently 400 MB) are highlighted in the UI and marked as warnings in the log output.
Note: - This tool is intended for runtime debugging and stability monitoring. - The monitor does not attempt to manage or reduce memory; it only reports.
- class gui.ui.monitor_memory.MonitorMemory(*args, **kwargs)[source]
Bases:
QWidgetPopup
QWidgetthat monitors and displays the current process memory usage.The widget periodically reads RSS memory usage using
psutiland:Appends log lines to
paths.MEMORY_LOG_FILE.Displays the log in a read-only
QTextEditin real time.Highlights entries in red when the warning threshold is exceeded.
- interval_input
Text input containing the monitoring interval in seconds.
- Type:
QLineEdit
- save_btn
Button that saves the interval to settings and applies it immediately.
- Type:
QPushButton
- text_area
Read-only area showing the rolling log output (styled by warning level).
- Type:
QTextEdit
- close_btn
Button that stops monitoring and closes the window.
- Type:
QPushButton
- timer
Periodic timer that triggers memory sampling.
- Type:
QTimer
- interval_sec
Effective monitoring interval in seconds (clamped to at least 1).
- Type:
int
- __init__(interval_sec=5, parent=None)[source]
Initialize the memory monitor widget and build the UI.
- Parameters:
interval_sec (int) – Initial monitoring interval in seconds. Values less than 1 are clamped to 1 when applied.
parent (QWidget, optional) – Optional parent widget.
- set_interval(interval_sec)[source]
Apply a new monitoring interval to the internal timer.
The value is clamped to at least 1 second.
- Parameters:
interval_sec (int) – Interval in seconds.
- save_interval()[source]
Save the user-entered interval to settings and apply it immediately.
Behavior:
Reads the interval from
self.interval_input.Updates
self.timerinterval.Persists the value to settings under
memory_interval_sec.Writes an info/error message into
self.text_area.
Note
This method only validates that the input can be parsed as an integer.
Non-integer input is treated as an error.
- record_and_display_memory()[source]
Sample current RSS memory usage, append it to the log file, and render it in the UI.
- Output format:
[<timestamp>] Memory: <MB> MB- Warning behavior:
If the sampled memory exceeds a fixed threshold (currently 400 MB), the log line is marked with
[WARNING]and colored red in the UI.- Failures:
Any unexpected exception is appended to the UI output area as plain text.