fix: MetaDrive simulator on macOS (spawn context, lazy imports)#38152
Closed
AmitabhainArunachala wants to merge 2 commits into
Closed
fix: MetaDrive simulator on macOS (spawn context, lazy imports)#38152AmitabhainArunachala wants to merge 2 commits into
AmitabhainArunachala wants to merge 2 commits into
Conversation
…onic timestamps) Fixes commaai#33207 Root causes: - multiprocessing defaults to fork on macOS, but Panda3D/Cocoa cannot safely initialize in a forked child after parent GUI state setup - Top-level imports of panda3d/metadrive modules initialize Cocoa in the parent process before the child is spawned - dist_threshold of 1 is too aggressive for macOS where simulator ticks produce smaller position deltas - Synthetic eof timestamp (frame_id * 0.05) fails camera freshness checks on macOS where frame timing differs - forkpty in unblock_stdout() is incompatible with macOS simulation Changes: - metadrive_world.py: use spawn context on Darwin, reduce dist_threshold - metadrive_process.py: lazy-load panda3d/metadrive inside subprocess - camerad.py: use time.monotonic() for eof timestamp - manager.py: skip forkpty on macOS when SIMULATION=1
Contributor
Process replay diff reportReplays driving segments through this PR and compares the behavior to master. ✅ 0 changed, 66 passed, 0 errors |
Author
|
Closing this in favor of #38156 which takes a cleaner approach with fewer changes and passes all CI checks. The spawn-context and lazy-import changes in this PR were addressing symptoms rather than root causes — |
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.
Summary
Fixes the MetaDrive simulator so it runs correctly on macOS, allowing
tools/sim/tests/test_metadrive_bridge.pyto pass.Closes #33207
Root causes
On macOS, Python's multiprocessing defaults to the fork start method. Panda3D and MetaDrive initialize Cocoa and OpenGL on import, which is unsafe in a forked child process after the parent has set up GUI state.
Additionally:
dist_threshold = 1is too aggressive on macOS where simulator ticks produce smaller position deltas, causing falsevehicle_not_movingfailureseof = frame_id * 0.05 * 1e9fails camera freshness checks on macOSforkptyinunblock_stdout()is incompatible with macOS simulationChanges
tools/sim/bridge/metadrive/metadrive_world.pymultiprocessing.get_context("spawn")on Darwin for clean subprocess statemp_ctx.{Array, Pipe, Event, Process}so all IPC primitives share the spawn contextdist_thresholdto0.05on macOS to avoid falsevehicle_not_movingfailurestools/sim/bridge/metadrive/metadrive_process.pypanda3dandmetadrive— these initialized Cocoa in the parent processapply_metadrive_patches()andmetadrive_process(), which run in the child subprocessC3_POSITION/C3_HPRconstants inside the lazy initializationtools/sim/lib/camerad.pytime.monotonic()for theeoftimestamp instead offrame_id * 0.05 * 1e9system/manager/manager.pyunblock_stdout()(which callsforkpty) on Darwin whenSIMULATION=1Testing