SG-42073 Fixes segmentation faults on Python 3.13 with PySide6 6.8.3+ on macOS#172
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #172 +/- ##
==========================================
+ Coverage 31.86% 31.87% +0.01%
==========================================
Files 68 68
Lines 7658 7658
==========================================
+ Hits 2440 2441 +1
+ Misses 5218 5217 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b6c4334 to
2359ce9
Compare
…e engine Python 3.13 with PySide6 6.8.3+ has stricter Qt object lifecycle management that causes segmentation faults when Qt objects with engine/app references are destroyed after the engine itself. Root Cause: - FileModel (_model) created in tests holds references to engine/app - pytest's addCleanup() runs AFTER tearDown(), destroying _model last - When _model.destroy() accesses freed engine memory -> segfault - Only affects Python 3.13 + PySide6 6.8.3+ due to stricter enforcement Solution: - Remove addCleanup() for engine and bg_task_manager - Implement explicit tearDown() with proper cleanup order: 1. Shut down background task manager + wait for threads 2. **CRITICAL FIX**: Destroy _model BEFORE engine.destroy() 3. Wait for metrics dispatcher threads to complete 4. Destroy engine 5. Final Qt event processing Testing: - Python 3.13.10 + PySide6 6.8.3: 14/15 runs successful (was ~40%) - Python 3.11 + PySide6 6.6.3: 5/5 runs successful (100%) - Follows tk-framework-shotgunutils cleanup pattern The key fix is 6 lines (lines 117-122) that explicitly destroy test-created Qt objects before engine destruction, preventing access to freed memory.
2359ce9 to
72adffe
Compare
There was a problem hiding this comment.
Pull request overview
Fixes intermittent segmentation faults in macOS test runs on Python 3.13 + PySide6 6.8.3+ by enforcing a deterministic Qt/engine teardown order (destroying test-created Qt objects before destroying the engine) and expanding async teardown waits.
Changes:
- Removed
addCleanup()for engine and background task manager in favor of an explicittearDown()with ordered cleanup. - Added explicit shutdown/waits for background/metrics dispatcher threads and aggressive Qt event processing during teardown.
- Increased default
wait_for()timeout from 2000ms to 5000ms.
Comments suppressed due to low confidence (1)
tests/python/workfiles2_test_base.py:1
- The
timeoutdocstring text is duplicated (“in milliseconds (default 5000ms) … in milliseconds (default 5000ms)”). Please fix to a single, clear description (e.g., “Timeout in milliseconds (default 5000ms).”).
# Copyright (c) 2020 Shotgun Software Inc.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
carlos-villavicencio-adsk
left a comment
There was a problem hiding this comment.
Great job 🚀
Fixes segmentation faults on Python 3.13 with PySide6 6.8.3+ on macOS.
Root Cause:
Python 3.13 with PySide6 6.8.3+ has stricter Qt object lifecycle management. Test-created FileModel objects hold references to engine/app, and pytest'"'"'s
addCleanup()destroys them AFTERtearDown()completes. When_model.destroy()tries to access the already-freed engine memory → segfault.Solution:
addCleanup()for engine and bg_task_managertearDown()with proper cleanup order:_modelBEFOREengine.destroy()Testing:
Key Fix:
6 lines (117-122) that explicitly destroy test-created Qt objects before engine destruction, preventing access to freed memory. Follows tk-framework-shotgunutils cleanup pattern.
Related: #171