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 9b8163b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 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_telemetry()

# Save current UI state.
state.latest_ui_values.update(latest)
Expand Down
23 changes: 20 additions & 3 deletions runtimepy/net/server/websocket/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,36 @@ def frame(self, time: float) -> JsonMessage:

return result

def clear_telemetry(self) -> None:
"""Clear all telemetry interactions."""

# 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 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 = []

self.clear_telemetry()

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

logger.addHandler(self.tab_logger)
self._loggers.append(logger)
if logger not in self._loggers:
logger.addHandler(self.tab_logger)
self._loggers.append(logger)

@staticmethod
def create() -> "TabState":
Expand Down

0 comments on commit 9b8163b

Please sign in to comment.