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 import_module with args ('tzdata',) inside the event loop #685

Open
kumarunster opened this issue Jan 18, 2025 · 3 comments

Comments

@kumarunster
Copy link

getting such exceptions and as a hint in log suggesting, creating a bug report here.

homeassistant  | ESC[33m2025-01-05 09:44:00.877 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('tzdata',) inside the event loop by custom integration 'pyscript' at custom_components/pyscript/eval.py, line 1982: return func(*args, **kwargs) (offender: /u
sr/local/lib/python3.12/site-packages/pandas/compat/_optional.py, line 132: module = importlib.import_module(name)), please create a bug report at https://github.com/custom-components/pyscript/issues
homeassistant  | For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "<frozen runpy>", line 198, in _run_module_as_main
homeassistant  |   File "<frozen runpy>", line 88, in _run_code
homeassistant  |   File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
homeassistant  |     sys.exit(main())
homeassistant  |   File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
homeassistant  |     exit_code = runner.run(runtime_conf)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run
homeassistant  |     return loop.run_until_complete(setup_and_run_hass(runtime_config))
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
homeassistant  |     self.run_forever()
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
homeassistant  |     self._run_once()
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
homeassistant  |     handle._run()
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
homeassistant  |     self._context.run(self._callback, *self._args)
homeassistant  |   File "/config/custom_components/pyscript/function.py", line 448, in run_coro
homeassistant  |     result = await coro
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 508, in do_service_call
homeassistant  |     retval = await func.call(ast_ctx, **data)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 800, in call
homeassistant  |     val = await self.try_aeval(ast_ctx, arg1)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 700, in try_aeval
homeassistant  |     return await ast_ctx.aeval(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 940, in aeval
homeassistant  |     val = await getattr(self, name, self.ast_not_implemented)(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1468, in ast_assign
homeassistant  |     rhs = await self.aeval(arg.value)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 940, in aeval
homeassistant  |     val = await getattr(self, name, self.ast_not_implemented)(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1918, in ast_call
homeassistant  |     func = await self.aeval(arg.func)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 940, in aeval
homeassistant  |     val = await getattr(self, name, self.ast_not_implemented)(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1568, in ast_attribute
homeassistant  |     val = await self.aeval(arg.value)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 940, in aeval
homeassistant  |     val = await getattr(self, name, self.ast_not_implemented)(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1568, in ast_attribute
homeassistant  |     val = await self.aeval(arg.value)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 940, in aeval
homeassistant  |     val = await getattr(self, name, self.ast_not_implemented)(arg)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1937, in ast_call
homeassistant  |     return await self.call_func(func, func_name, *args, **kwargs)
homeassistant  |   File "/config/custom_components/pyscript/eval.py", line 1982, in call_func
homeassistant  |     return func(*args, **kwargs)
homeassistant  | ESC[0m

@ALERTua
Copy link
Contributor

ALERTua commented Jan 18, 2025

please provide the code block that causes this

@kumarunster
Copy link
Author

my code just importing pandas:

...
import pandas as pd
...

and as in log visible at /usr/local/lib/python3.12/site-packages/pandas/compat/_optional.py line 132

https://github.com/pandas-dev/pandas/blob/main/pandas/compat/_optional.py

    msg = (                                                                 
        f"Missing optional dependency '{install_name}'. {extra} "           
        f"Use pip or conda to install {install_name}."                      
    )                                                                       
    try:                                                                    
        module = importlib.import_module(name)   # <--- thats line 132                            
    except ImportError:                                                     
        if errors == "raise":                                               
            raise ImportError(msg)                                          
        return None                                                        

@spmatich
Copy link

I am also seeing this message in the homeassistant log.
Looks like it just fires once after a restart of homeassistant.
first message in log after restart:
2025-02-27 04:13:11.992 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

then 10 minutes later , which I guess is how long it blocks for:
2025-02-27 04:23:20.093 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('tzdata',) inside the event loop by custom integration 'pyscript' at custom_components/pyscript/eval.py, line 1905: return var[await self.aeval(arg.slice)] (offender: /usr/local/lib/python3.12/site-packages/pandas/compat/_optional.py, line 132: module = importlib.import_module(name)), 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/#import_module 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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/eval.py", line 508, in do_service_call retval = await func.call(ast_ctx, **data) 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 1034, in ast_if 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 1905, in ast_subscript return var[await self.aeval(arg.slice)]

The pandas module import works fine (eventually?)
import pandas as pd

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

3 participants