Skip to content

Fix Qt threading violation in MainThreadRunner initialization#41

Merged
iamtekson merged 6 commits intodevfrom
copilot/sub-pr-38
Jan 5, 2026
Merged

Fix Qt threading violation in MainThreadRunner initialization#41
iamtekson merged 6 commits intodevfrom
copilot/sub-pr-38

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 5, 2026

MainThreadRunner is a QObject that was being instantiated in __init__(), which may execute on any thread. Qt objects must be created on the thread where they will live to avoid threading violations.

Changes:

  • Moved MainThreadRunner instantiation from __init__() to initGui(), which QGIS guarantees runs on the main thread
  • Initialize self.main_runner = None in __init__()
  • Added defensive check in run() with warning log if initGui() was not called properly
  • Updated stale comment in canvas_refresh.py referencing old initialization location

Before:

def __init__(self, iface):
    self.iface = iface
    self.main_runner = MainThreadRunner()  # Wrong thread

After:

def __init__(self, iface):
    self.iface = iface
    self.main_runner = None  # Deferred

def initGui(self):
    self.main_runner = MainThreadRunner()  # Main thread guaranteed

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 5, 2026 05:34
Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
Co-authored-by: iamtekson <39838116+iamtekson@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on illegal threading issue resolution Fix Qt threading violation in MainThreadRunner initialization Jan 5, 2026
@iamtekson iamtekson marked this pull request as ready for review January 5, 2026 05:38
Copilot AI requested a review from iamtekson January 5, 2026 05:39
@iamtekson iamtekson merged commit ec61662 into dev Jan 5, 2026
1 check passed
@iamtekson iamtekson deleted the copilot/sub-pr-38 branch January 5, 2026 05:39
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