Skip to content

Fix MetaDrive simulator on macOS (spawn context, lazy imports, timestamp fix)#37770

Open
mirathfan wants to merge 1 commit intocommaai:masterfrom
mirathfan:fix/metadrive-macos
Open

Fix MetaDrive simulator on macOS (spawn context, lazy imports, timestamp fix)#37770
mirathfan wants to merge 1 commit intocommaai:masterfrom
mirathfan:fix/metadrive-macos

Conversation

@mirathfan
Copy link
Copy Markdown

Description

Fixes #33207

Fix MetaDrive simulator support on macOS by addressing process startup and timing issues in the sim path.

Root causes:

  • manager.py used unblock_stdout() / forkpty, which is unsafe in this macOS simulation path startup once Cocoa/Panda3D paths are involved
  • MetaDrive subprocess startup used the default multiprocessing behavior, which is not safe enough for this macOS path
  • Panda3D / MetaDrive imports happened too early in the parent process
  • Sim camera EOF timestamps were synthetic instead of monotonic, which caused downstream freshness issues
  • Movement detection during the macOS test run was too strict and could incorrectly report vehicle_not_moving

Fixes:

  • Skip unblock_stdout() on Darwin when SIMULATION=1
  • Lazy-load Panda3D / MetaDrive in the subprocess path
  • Use multiprocessing "spawn" context on macOS for MetaDrive world to avoid fork-related instability with Cocoa/Panda3D
  • Use time.monotonic() for sim camera EOF timestamps
  • Lower movement threshold only for Darwin test runs to avoid false "vehicle_not_moving" detection due to smaller per-step motion

Verification

Ran locally on macOS:

python -m pytest -vv -s -n0 tools/sim/tests/test_metadrive_bridge.py

Result:

1 passed, 1 skipped

…context, lazy-load Panda3D, and correct camera timestamps
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get MetaDrive simulator working on macOS

1 participant