pnbruckner / ha-sun2

Home Assistant Sun2 Sensor
The Unlicense
235 stars 22 forks source link

[2024.6.0b0]: Detected blocking call to open inside the event loop by custom integration 'sun2' #125

Closed krazos closed 5 months ago

krazos commented 5 months ago

Log warning in core-2024.6.0b0:

Logger: homeassistant.util.loop Source: util/loop.py:81 First occurred: 11:50:42 AM (665 occurrences) Last logged: 11:51:39 AM

Detected blocking call to open inside the event loop by custom integration 'sun2' at customcomponents/sun2/helpers.py, line 369: return getattr(loc, event.split("")[1])(date_or_dttm) (offender: /usr/local/lib/python3.12/site-packages/pytz/init.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/pnbruckner/ha-sun2/issues

pnbruckner commented 5 months ago

Thanks. Didn't realize pytz did that. I'll fix it.

pnbruckner commented 5 months ago

Oh, wait, my integration doesn't use pytz, at least not directly. It uses the astral package, which HA does also (for the sun integration, and sun triggers), and astral must use pytz, either directly or indirectly. I wonder how HA deals with that...

pnbruckner commented 5 months ago

I can't see where HA is dealing with this. Not sure what I can do about this.

pnbruckner commented 5 months ago

@bdraco, hope you don't mind me tagging you. Any ideas?

bdraco commented 5 months ago

This should help

https://developers.home-assistant.io/blog/2024/05/19/fix_zoneinfo_blocking_io/

pnbruckner commented 5 months ago

Thanks! I'll probably have to make changes accordingly.

I also just discovered that HA's built-in code that uses the astral package (probably) always calls functions with "local=False", whereas my integration leaves that out and so uses the default of "local=True". That causes astral's functions to make calls into pytz (2.2 still used pytz as opposed to zoneinfo which I think it started using in 3.0) that ultimately will do file I/O.

pnbruckner commented 5 months ago

@krazos, please let me know if version 3.3.2 fixes the problem for you.

krazos commented 5 months ago

Thanks, @pnbruckner, for jumping on this fix. So far so good on v3.3.2!