hasscc / hass-edge-tts

🗣️ Microsoft Edge TTS for Home Assistant, no need for app_key
363 stars 62 forks source link

Detected blocking call #49

Open demey opened 4 months ago

demey commented 4 months ago

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 commented 2 weeks ago

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 commented 1 week ago

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 commented 1 week ago

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.