diff --git a/homeassistant/runner.py b/homeassistant/runner.py index 26e7bab7616..b397f9438f2 100644 --- a/homeassistant/runner.py +++ b/homeassistant/runner.py @@ -11,6 +11,18 @@ from homeassistant import bootstrap from homeassistant.core import callback from homeassistant.helpers.frame import warn_use +# +# Python 3.8 has significantly less workers by default +# than Python 3.7. In order to be consistent between +# supported versions, we need to set max_workers. +# +# In most cases the workers are not I/O bound, as they +# are sleeping/blocking waiting for data from integrations +# updating so this number should be higher than the default +# use case. +# +MAX_EXECUTOR_WORKERS = 64 + @dataclasses.dataclass class RuntimeConfig: @@ -57,7 +69,9 @@ class HassEventLoopPolicy(PolicyBase): # type: ignore if self.debug: loop.set_debug(True) - executor = ThreadPoolExecutor(thread_name_prefix="SyncWorker") + executor = ThreadPoolExecutor( + thread_name_prefix="SyncWorker", max_workers=MAX_EXECUTOR_WORKERS + ) loop.set_default_executor(executor) loop.set_default_executor = warn_use( # type: ignore loop.set_default_executor, "sets default executor on the event loop"