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

Detected blocking call to open with args ('/usr/local/lib/python3.13/site-packages/pytz/zoneinfo/Africa/Abidjan', 'rb') #687

Closed
redlefloh opened this issue Jan 21, 2025 · 6 comments

Comments

@redlefloh
Copy link

I am getting this warning which suggests to file a bug here. Running the latest HA Version 2025.1.3. Any advice what to do? Thanks!

2025-01-21 23:04:59.386 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/usr/local/lib/python3.13/site-packages/pytz/zoneinfo/Africa/Abidjan', 'rb') inside the event loop by custom integration 'pyscript' at custom_components/pyscript/eval.py, line 1982: return func(*args, **kwargs) (offender: /usr/local/lib/python3.13/site-packages/pytz/__init__.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/custom-components/pyscript/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/pyscript/function.py", line 448, in run_coro
    result = await coro
  File "/config/custom_components/pyscript/trigger.py", line 1380, in do_func_call
    await ast_ctx.call_func(func, None, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 1952, in call_func
    return await func.call(self, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 800, in call
    val = await self.try_aeval(ast_ctx, arg1)
  File "/config/custom_components/pyscript/eval.py", line 700, in try_aeval
    return await ast_ctx.aeval(arg)
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1224, in ast_try
    val = await self.aeval(arg1)
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1468, in ast_assign
    rhs = await self.aeval(arg.value)
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1937, in ast_call
    return await self.call_func(func, func_name, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 1952, in call_func
    return await func.call(self, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 852, in call
    return await self.func.call(ast_ctx, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 800, in call
    val = await self.try_aeval(ast_ctx, arg1)
  File "/config/custom_components/pyscript/eval.py", line 700, in try_aeval
    return await ast_ctx.aeval(arg)
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1468, in ast_assign
    rhs = await self.aeval(arg.value)
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1925, in ast_call
    args = await self.eval_elt_list(arg.args)
  File "/config/custom_components/pyscript/eval.py", line 1765, in eval_elt_list
    val.append(await self.aeval(arg))
  File "/config/custom_components/pyscript/eval.py", line 940, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1937, in ast_call
    return await self.call_func(func, func_name, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 1982, in call_func
    return func(*args, **kwargs)
@craigbarratt
Copy link
Member

The problem is likely in the pyscript code you are running. Are your scripts calling import_module directly or something similar?

@craigbarratt
Copy link
Member

Please review this section of the docs.

@redlefloh
Copy link
Author

Thanks @craigbarratt for taking a look, I do not use import_module in my pyscript code and the traces in the logs seem to all coming from within pyscript, at least I can't identify any reference to my own code, but maybe I am missing something?

@craigbarratt
Copy link
Member

craigbarratt commented Jan 23, 2025

Ah good point. I looked at this some more. pytz uses lazy loading (ie, defers loading specific timezone data files until needed). That's really problematic, since that means it will happen during use, not initialization.

pyscript doesn't use pytz or timezones. Does your code use it? If so, you could use zoneinfo instead, which I believe is in the standard library for python >= 3.9. I'm not sure though if it uses lazy loading too...

Another workaround is to call pytz with the right timezone in one of your scripts outside of any function, so that it is executed during load. Hopefully then it won't re-load the same timezone information later.

@redlefloh
Copy link
Author

fantastic, yes, I was using pytz. I changed it to zoneinfo and it does seem to do the trick!
Thank you so much @craigbarratt

@redlefloh
Copy link
Author

thanks again @craigbarratt, closing this as resolved.

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

2 participants