Skip to content

SG-42073 Fixes segmentation faults on Python 3.13 with PySide6 6.8.3+ on macOS#172

Merged
julien-lang merged 1 commit intomasterfrom
ticket/SG-42069-fix-segfault-python-313
Feb 11, 2026
Merged

SG-42073 Fixes segmentation faults on Python 3.13 with PySide6 6.8.3+ on macOS#172
julien-lang merged 1 commit intomasterfrom
ticket/SG-42069-fix-segfault-python-313

Conversation

@julien-lang
Copy link
Member

@julien-lang julien-lang commented Feb 10, 2026

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 AFTER tearDown() completes. When _model.destroy() tries to access the already-freed engine memory → segfault.

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: ✅ 100% success
  • All CI platforms passing

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

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.87%. Comparing base (c93ee8a) to head (72adffe).
⚠️ Report is 1 commits behind head on master.

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     
Flag Coverage Δ
Linux 31.87% <ø> (+0.01%) ⬆️
Python-3.10 31.86% <ø> (ø)
Python-3.11 31.86% <ø> (ø)
Python-3.13 31.86% <ø> (+0.01%) ⬆️
Python-3.9 31.88% <ø> (+0.01%) ⬆️
Windows 18.69% <ø> (ø)
macOS 31.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@julien-lang julien-lang force-pushed the ticket/SG-42069-fix-segfault-python-313 branch 2 times, most recently from b6c4334 to 2359ce9 Compare February 10, 2026 23:34
@julien-lang julien-lang changed the title SG-42069: Fix segfault in Python 3.13 SG-42073 Fix segfault in Python 3.13 Feb 11, 2026
…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.
@julien-lang julien-lang force-pushed the ticket/SG-42069-fix-segfault-python-313 branch from 2359ce9 to 72adffe Compare February 11, 2026 19:26
@julien-lang julien-lang changed the title SG-42073 Fix segfault in Python 3.13 SG-42073: Fix Python 3.13 segfault by destroying test models before engine Feb 11, 2026
@julien-lang julien-lang changed the title SG-42073: Fix Python 3.13 segfault by destroying test models before engine SG-42073 Fixes segmentation faults on Python 3.13 with PySide6 6.8.3+ on macOS Feb 11, 2026
@julien-lang julien-lang requested a review from Copilot February 11, 2026 19:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explicit tearDown() 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 timeout docstring 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.

@julien-lang julien-lang marked this pull request as ready for review February 11, 2026 19:37
@julien-lang julien-lang requested a review from a team February 11, 2026 19:44
Copy link
Contributor

@carlos-villavicencio-adsk carlos-villavicencio-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 🚀

@julien-lang julien-lang merged commit 8c73e7b into master Feb 11, 2026
25 checks passed
@julien-lang julien-lang deleted the ticket/SG-42069-fix-segfault-python-313 branch February 11, 2026 20:00
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.

2 participants

Comments