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 #49

Open
demey opened this issue Jul 26, 2024 · 3 comments
Open

Detected blocking call #49

demey opened this issue Jul 26, 2024 · 3 comments

Comments

@demey
Copy link

demey commented Jul 26, 2024

Home Assistant
Core 2024.7.3
Supervisor 2024.06.2
Operating System 12.4

WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/root/.netrc',) inside the event loop by custom integration 'edge_tts' at custom_components/edge_tts/tts.py, line 408: async for chunk in tts.stream(): (offender: /usr/local/lib/python3.12/netrc.py, line 74: with open(file, encoding="utf-8") as fp:), please create a bug report at https://github.com/hasscc/hass-edge-tts/issues

For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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 190, 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 "/usr/src/homeassistant/homeassistant/components/tts/init.py", line 727, in get_tts_data
extension, data = await engine_instance.async_get_tts_audio(
File "/config/custom_components/edge_tts/tts.py", line 408, in async_get_tts_audio
async for chunk in tts.stream():

@demey
Copy link
Author

demey commented Nov 10, 2024

Issue still exists.
HA version 2024.11.1

`2024-11-10 22:50:34.006 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f63cb67a350>, '/usr/local/lib/python3.12/site-packages/certifi/cacert.pem', None, None) inside the event loop by custom integration 'edge_tts' at custom_components/edge_tts/tts.py, line 408: async for chunk in tts.stream(): (offender: /usr/local/lib/python3.12/ssl.py, line 708: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/hasscc/hass-edge-tts/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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 "/usr/src/homeassistant/homeassistant/components/tts/init.py", line 767, in get_tts_data
extension, data = await engine_instance.async_get_tts_audio(
File "/config/custom_components/edge_tts/tts.py", line 408, in async_get_tts_audio
async for chunk in tts.stream():

2024-11-10 22:50:34.014 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/root/.netrc',) inside the event loop by custom integration 'edge_tts' at custom_components/edge_tts/tts.py, line 408: async for chunk in tts.stream(): (offender: /usr/local/lib/python3.12/netrc.py, line 74: with open(file, encoding="utf-8") as fp:), please create a bug report at https://github.com/hasscc/hass-edge-tts/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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 "/usr/src/homeassistant/homeassistant/components/tts/init.py", line 767, in get_tts_data
extension, data = await engine_instance.async_get_tts_audio(
File "/config/custom_components/edge_tts/tts.py", line 408, in async_get_tts_audio
async for chunk in tts.stream():`

@demey
Copy link
Author

demey commented Nov 16, 2024

I have changed line 408 in /config/custom_components/edge_tts/tts.py
from async for chunk in tts.stream(): to for chunk in tts.stream_sync(): and listed WARNINGs disappeared.
Integration works as expected.

@rany2
Copy link
Collaborator

rany2 commented Nov 17, 2024

I think the detection is a false positive. At least I can't find any blocking code for edge-tts that can cause this.

The reason the sync varient doesn't trigger it is likely because it starts a new event loop in a new thread which is likely not monitored by Home Assistant.

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