Skip to content

Commit

Permalink
Attempt to aid memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Nov 2, 2024
1 parent 71edea3 commit a25f616
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 1 addition & 3 deletions runtimepy/net/server/app/env/tab/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def handle_shown_state(
for name in env.names:
self._setup_callback(name, state)
else:
# Remove callbacks for primitives.
for name, val in state.callbacks.items():
state.primitives[name].remove_callback(val)
state.clear_loggers()

# Save current UI state.
state.latest_ui_values.update(latest)
Expand Down
13 changes: 12 additions & 1 deletion runtimepy/net/server/websocket/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,21 @@ def frame(self, time: float) -> JsonMessage:
def clear_loggers(self) -> None:
"""Clear all logging handlers."""

# Remove handlers.
for logger in self._loggers:
logger.removeHandler(self.tab_logger)
self._loggers.clear()

self.tab_logger.drain_str()
self._loggers = []

# Remove callbacks for primitives.
for name, val in self.callbacks.items():
self.primitives[name].remove_callback(val)
self.callbacks.clear()
self.primitives.clear()

# Clear points.
self.points.clear()

def add_logger(self, logger: logging.Logger) -> None:
"""Add a logger."""
Expand Down

0 comments on commit a25f616

Please sign in to comment.