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 thread safety to queue access in GPIOQueue - fix #975 #1040

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

Conversation

chaddcw
Copy link

@chaddcw chaddcw commented Apr 30, 2022

No description provided.

@bennuttall
Copy link
Member

Thanks! @waveform80 will you take a look?

@jogi-k
Copy link

jogi-k commented May 8, 2022

Suddenly - after about 10 month working without any problems 24/7 - this issue occurred reproducible in my application, it didn't work any longer. I applied the pull-request on my installation. It works perfectly.

👍

@@ -577,9 +579,11 @@ def fill(self):
while not self.stopping.wait(self.sample_wait):
value = self.parent._read()
if value not in self.ignore:
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, if the value is in self.ignore, then I guess self.queue won't get appended to, and therefore len(self.queue) won't change, and therefore there's no chance of self.full getting set either?
I.e. perhaps this function could change to:

    def fill(self):
        try:
            while not self.stopping.wait(self.sample_wait):
                value = self.parent._read()
                if value not in self.ignore:
                    with self.lock:
                        self.queue.append(value)
                        if not self.full.is_set() and len(self.queue) >= self.queue.maxlen:
                            self.full.set()
                    if (self.partial or self.full.is_set()) and isinstance(self.parent, EventsMixin):
                        self.parent._fire_events(self.parent.pin_factory.ticks(), self.parent.is_active)
        except ReferenceError:
            # Parent is dead; time to die!
            pass

?

Copy link
Author

Choose a reason for hiding this comment

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

Moving the middle if in the function inside the first lock (and eliminating the second with self.lock:) looks like a good change.

I'm not sure about that last if in the function being protected by if value not in self.ignore:

The existing code allows self.parent._fire_events() to be activated when value is in self.ignore and self.partial is set. The suggested change won't allow that to happen.

Thoughts?

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.

None yet

4 participants