From 09e7156d2d272e5489c7d6c4516af677cb6070c1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 23 May 2024 04:50:25 -1000 Subject: [PATCH] Fix turbojpeg init doing blocking I/O in the event loop (#117971) * Fix turbojpeg init doing blocking I/O in the event loop fixes ``` Detected blocking call to open inside the event loop by integration camera at homeassistant/components/camera/img_util.py, line 100: TurboJPEGSingleton.__instance = TurboJPEG() (offender: /usr/local/lib/python3.12/ctypes/util.py, line 276: with open(filepath, rb) as fh:), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+camera%22 ``` * Update homeassistant/components/camera/img_util.py * Fix turbojpeg init doing blocking I/O in the event loop fixes ``` Detected blocking call to open inside the event loop by integration camera at homeassistant/components/camera/img_util.py, line 100: TurboJPEGSingleton.__instance = TurboJPEG() (offender: /usr/local/lib/python3.12/ctypes/util.py, line 276: with open(filepath, rb) as fh:), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+camera%22 ``` * already suppressed and logged --- homeassistant/components/camera/img_util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/camera/img_util.py b/homeassistant/components/camera/img_util.py index 8ce8d51c812..bbe85bf82db 100644 --- a/homeassistant/components/camera/img_util.py +++ b/homeassistant/components/camera/img_util.py @@ -103,3 +103,9 @@ class TurboJPEGSingleton: "Error loading libturbojpeg; Camera snapshot performance will be sub-optimal" ) TurboJPEGSingleton.__instance = False + + +# TurboJPEG loads libraries that do blocking I/O. +# Initialize TurboJPEGSingleton in the executor to avoid +# blocking the event loop. +TurboJPEGSingleton.instance()