yaq-project / yaq-python

Repository for yaq core python packages.
https://yaq.fyi
GNU Lesser General Public License v3.0
6 stars 5 forks source link

sensors: stop _measure, update_state as part of close #28

Closed ddkohler closed 2 years ago

ddkohler commented 2 years ago

_measure often follows the following syntax:

def _measure(self):
    while True:
        try:
            ...
        except Exception as e:
            continue
    return measure_dict

If a daemon uses the close method while looping (e.g. usb resources are told to close), _measure may try to initiate communication after comms close, which triggers an infinite loop of exceptions. As a result, the daemon never closes, and client restart commands fail. It's a nasty form of failure because I'm not sure many daemon devs would realize this could happen. It is not 100% reproducible either (I am seeing it ~20% of the time on my particular daemon).

I propose we give is-sensor a close method that stops the looping. But I'm not sure this is possible, and I'm also not sure it's a great solution. Daemon devs would have to make sure that daemons use the trait close method prior to any hardware disconnect commands.

ddkohler commented 2 years ago

Summary of discussion with @ksunden

In light of this, we have decided that this issue will be addressed within individual daemons and will not be a trait implementation.

Personally, I found this issue a useful lesson on how to implement async commands carefully (e.g. even consider failures).