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

Thread safety in set_value #77

Open
thomaspurchas opened this issue Apr 2, 2018 · 4 comments
Open

Thread safety in set_value #77

thomaspurchas opened this issue Apr 2, 2018 · 4 comments
Labels

Comments

@thomaspurchas
Copy link

@ikalchev do you have any docs covering thread safety? I know elaborated about how threads are used in #74, but it looks like characteristics set_value() is not really thread safe, while being called from multiple threads.

Also do you offer guidance anywhere for how an accessories run() loop should interact with requests from py-HAP in a thread safe manner?

@cdce8p
Copy link
Contributor

cdce8p commented Apr 2, 2018

Regarding set_value: You might be right here. What if the user calls set_value at the same time, when the value is changed in HomeKit and set_characteristics calls set_value?

Regarding run(): I don't think there is currently. Although set_value might not be threadsafe as described above, I think this method should be the point of connection here.

@ikalchev
Copy link
Owner

ikalchev commented Apr 2, 2018

set_value is not thread-safe that's true - the server thread can set that as part of handling a user request, while in the same time the Accessory thread can set it. Ops.

@ikalchev ikalchev added the bug label Apr 2, 2018
@ikalchev ikalchev changed the title Thread safety Thread safety in set_value Apr 2, 2018
@ikalchev
Copy link
Owner

ikalchev commented Apr 2, 2018

The chars are the only shared state, which are solely manipulated through set_value. At least I cannot recall another such place.

@shred86
Copy link

shred86 commented Dec 30, 2018

Could this possibly be an explanation to an issue I’m having with Home Assistant and HomeKit?

home-assistant/core#19604

I noticed in the logs when I’m having the issue mentioned in that post, set_value is not executed. When everything works as expected, I can see set_value being executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants