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

remove superfluous lock #825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

smurfix
Copy link

@smurfix smurfix commented Mar 11, 2024

Assigning to a variable is atomic anyway.
The lock is thus superfluous.

Assigning to a variable is atomic anyway.
The lock is thus superfluous.
Copy link
Contributor

@PierreF PierreF left a comment

Choose a reason for hiding this comment

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

What's the issue we try to solve by removing the locks ?

To my knowledge, this is safe to remove on CPython due to GIL and that Python bytecode are atomic. I don't known if this fact is documented by Python / CPython. I'm not sure this hold for other Python implementation (PyPy, Jython...) and I'm also unsure Python recommend relying on bytecode being atomic.

@@ -3001,8 +2983,7 @@ def handle_mytopic(client, userdata, message):
if callback is None or sub is None:
raise ValueError("sub and callback must both be defined.")

with self._callback_mutex:
self._on_message_filtered[sub] = callback
self._on_message_filtered[sub] = callback
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a simple assignment. I'm unsure whether this is safe to remove the lock.

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