Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-disconnecting mixin for QObject #5951

Closed
wants to merge 1 commit into from

Conversation

drew2a
Copy link
Contributor

@drew2a drew2a commented Jan 22, 2021

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:

                logger.info(f'Signal: {signal}')

And when trying to use (some) of the signals as a key in a dictionary:

                self.connected_signals[signal] += 1

Another case. Some signals lead to a python crash if you try to disconnect all callbacks at once:

                signal.disconenct()

Therefore:

  • id(signal) is using for logging and as a key for a dictionary
  • a full disconnect is performed by calling callback-by-callback disconnect.

Conclusion

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?

logger = logging.getLogger('QAutoDisconnectingMixin')


class QAutoDisconnectingMixin:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main improvement for the PR.

@ichorid
Copy link
Contributor

ichorid commented Jan 25, 2021

Indeed, connecting/disconnecting signals is a fragile topic in PyQT. I'm afraid it can bring more trouble because of potential interference with different QT version on different platforms, etc. I would prefer adding a separate warning ("caveat") chapter to our developer's guidelines instead. And of course, point out the PR reviewers to pay special attention to signals.

@drew2a drew2a changed the title WIP Add auto-disconnecting mixin for QObject Add auto-disconnecting mixin for QObject Jan 26, 2021
@drew2a drew2a marked this pull request as ready for review January 26, 2021 09:57
@sonarcloud
Copy link

sonarcloud bot commented Jan 26, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.3% 0.3% Duplication

@drew2a drew2a closed this Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants