Camera local_file - getting Bad File Descriptor Error - help needed

Hi,

I’m getting infrequent erorrs while using the camera.local_file component.

ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140154635488560] Error handling message: {'type': 'camera_thumbnail', 'entity_id': 'camera.local_file', 'id': 12493}
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/websocket_api/decorators.py", line 17, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/app/homeassistant/components/camera/__init__.py", line 463, in websocket_camera_thumbnail
    image = await async_get_image(hass, msg['entity_id'])
  File "/usr/src/app/homeassistant/components/camera/__init__.py", line 93, in async_get_image
    image = await camera.async_camera_image()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/camera/local_file.py", line 72, in camera_image
    with open(self._file_path, 'rb') as file:
OSError: [Errno 9] Bad file descriptor

this is my config:

  - platform: local_file
    file_path: /config/tmp/latest.jpg

I’m scanning a camera picture via tensorflow for persons (via a motion trigger), and when a person is detected the picture is beeing saved:

image_processing:
  - platform: tensorflow
    scan_interval: 20000
    source:
      - entity_id: camera.test
    model:
      graph: /config/tensorflow/frozen_inference_graph.pb
      categories:
        - person
    file_out:
      - "/config/tmp/latest.jpg"

Has anyone experienced the same and may point me in the right direction?
I’m running HA in a Docker on my NAS with 2.4Ghz QuadCore and 16MB Ram, performance should not be an issue.

Thanks!

Maybe try specifying the full pathname for the file…
That’s what I have for my camera and it works.

Thank you for your reply!
It is actually working, the file gets saved and can be read, but from time to time (still elaborating on the root cause) I get the ERROR mentioned above. So I assume the path is correct and accesible from HA.
What I am thinking about right now is that it may be due to simultaneous access
image_processing writes jpg and at the same time camera.local_file tries to load the file…

I’ve verified that the paths are accessible and there are no race conditions regarding “tensorflow image processing” causing this.

Related Issue on GitHub
https://github.com/home-assistant/home-assistant/issues/21090