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

sensor.py - RuntimeError: dictionary changed size during iteration #10

Open
larobo opened this issue May 2, 2023 · 0 comments
Open

Comments

@larobo
Copy link

larobo commented May 2, 2023

When the pop() runs from the code below:

sensor.py:
        for measurement_time in self._measurements.keys():
            if measurement_time < (now - self._period):
                _LOGGER.debug(
                    "period_rain update_data_from_sensor removed (%s: %s)",
                    datetime.fromtimestamp(measurement_time).isoformat(),
                    self._measurements[measurement_time]
                )
                self._measurements.pop(measurement_time)
            else:
                total += self._measurements[measurement_time]

you get the exception:
RuntimeError: dictionary changed size during iteration

A possible fix is:
for measurement_time in list(self._measurements.keys()):

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

No branches or pull requests

1 participant