Summary
GtpyAbstractScriptingWizardPage exposes package objects to the Python context so that scripts can access them during evaluation. These package objects are cloned in GtpyAbstractScriptingWizardPage::loadPackages() on the GUI thread, parented to the wizard page, and inserted into the Python context.
Script evaluation is later started asynchronously in GtpyAbstractScriptingWizardPage::evalScript() by creating a GtpyScriptRunnable and submitting it to the global QThreadPool.
As a result, the Python context contains QObject-based package objects with GUI-thread affinity, while the Python script itself is executed on a different thread.
If the script accesses one of these package objects and triggers functionality that depends on QObject thread affinity, Qt reports thread-affinity assertions.
In a nutshell
The wizard currently does this:
- Clone package objects on the GUI thread.
- Add those objects to the Python context.
- Run the Python script in a worker thread via
GtpyScriptRunnable.
- Allow the script to access the injected package objects from that worker thread.
This is unsafe because the package objects retain GUI-thread affinity while being accessed from a worker thread.
Expected Behaviour
Package objects exposed to Python should only be accessed from the thread that owns them.
Possible Fix
Ensure that both the package objects and the Python evaluation run on the same thread, e.g. move the objects to the evaluation thread before execution. The key requirement is that object access and thread affinity must match.
Summary
GtpyAbstractScriptingWizardPageexposes package objects to the Python context so that scripts can access them during evaluation. These package objects are cloned inGtpyAbstractScriptingWizardPage::loadPackages()on the GUI thread, parented to the wizard page, and inserted into the Python context.Script evaluation is later started asynchronously in
GtpyAbstractScriptingWizardPage::evalScript()by creating aGtpyScriptRunnableand submitting it to the globalQThreadPool.As a result, the Python context contains
QObject-based package objects with GUI-thread affinity, while the Python script itself is executed on a different thread.If the script accesses one of these package objects and triggers functionality that depends on
QObjectthread affinity, Qt reports thread-affinity assertions.In a nutshell
The wizard currently does this:
GtpyScriptRunnable.This is unsafe because the package objects retain GUI-thread affinity while being accessed from a worker thread.
Expected Behaviour
Package objects exposed to Python should only be accessed from the thread that owns them.
Possible Fix
Ensure that both the package objects and the Python evaluation run on the same thread, e.g. move the objects to the evaluation thread before execution. The key requirement is that object access and thread affinity must match.