Fix/python memoryleak replay#2002
Closed
bogwi wants to merge 6 commits intodimensionalOS:devfrom
Closed
Conversation
…ngs on mac; refactor timed_playback for improved threading and emission handling; use MultipleAssignmentDisposable
…) and MultipleAssignmentDisposable(); make it run on a threading.Thread we start explicitly.
…ilures are forwarded with observer.on_error(exc).
Contributor
|
hm this bugs me a bit, two things:
are we sure it isn't something simpler, like we are not garbage collecting messages after passing them down to subscribers? |
Contributor
|
yeah, issue was garbage collection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
dimos --dtop --replay run unitree-go2causes one of the Python processes to grow in memory. Even if the dimos-viewer was closed midway the replay that would not change anything and the memory would still grow.The problem was discussed by @leshy and @aclauer .
Previously, the code was doing this:
delay = target_time - current_time
If delay is negative, emit the frame immediately to catch up.
This meant that if the playback fell behind by 0.5 seconds, it would try to emit 500 milliseconds worth of video, lidar, and odometry frames instantly to catch up.
Solution
Re-Anchoring on Delay: Added a death spiral breaker logic. If the stream detects that it has fallen behind by more than 0.2 seconds (200 milliseconds), instead of trying to catch up with an instantaneous stream of frames, it re-anchors the time to the current frame (start_local_time = time.time()).
Precise Blocking Sleep: Replaced the manual chunked time.sleep() loop with threading.Event().wait(delay). This provides single-call sleep mechanism that has practically zero drift, completely preventing the systematic time accumulation over long playbacks, while still allowing instant cancellation if you stop the replay.