Add auto-disconnecting mixin for QObject #5951
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a Mixin that can disconnect QR signals automatically.
Based on the discussoin #5949 and regarding @ichorid experience, it is necessary to manually disconnect a QT signal. This should help for avoiding memory leaks like #5934
The current version of the Mixin is working with no errors (at least for me).
The pitfalls
During developing this Mixin I saw a lot of "strange" bugs when python crashed with the following error: "Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)".
They occurred, for example, when trying to log some of the signals:
And when trying to use (some) of the signals as a key in a dictionary:
Another case. Some signals lead to a python crash if you try to disconnect all callbacks at once:
Therefore:
id(signal)
is using for logging and as a key for a dictionaryConclusion
The Mixing is working for me with no errors, but I consider the QT disconnect mechanism is fragile.
Unfortunately, I see more risks for merging this PR rather than benefits.
What do you think about that?