379843eb54be1f26382ac2e98a76a36cfd3810e5,homeassistant/components/generic/camera.py,GenericCamera,async_camera_image,#GenericCamera#,127

Before Change


    async def async_camera_image(self):
        Return a still image response from the camera.
        try:
            url = self._still_image_url.async_render(parse_result=False)
        except TemplateError as err:
            _LOGGER.error("Error parsing template %s: %s", self._still_image_url, err)
            return self._last_image

        if url == self._last_url and self._limit_refetch:
            return self._last_image

        try:
            async_client = get_async_client(self.hass, verify_ssl=self.verify_ssl)
            response = await async_client.get(
                url, auth=self._auth, timeout=GET_IMAGE_TIMEOUT
            )
            response.raise_for_status()
            self._last_image = response.content
        except httpx.TimeoutException:
            _LOGGER.error("Timeout getting camera image from %s", self._name)
            return self._last_image

After Change


        Wrap _async_camera_image with an asyncio.shield.
        // Shield the request because of https://github.com/encode/httpx/issues/1461
        try:
            self._last_url, self._last_image = await asyncio.shield(
                self._async_camera_image()
            )
        except asyncio.CancelledError as err:
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: home-assistant/home-assistant
Commit Name: 379843eb54be1f26382ac2e98a76a36cfd3810e5
Time: 2021-03-30
Author: 46082645+uvjustin@users.noreply.github.com
File Name: homeassistant/components/generic/camera.py
Class Name: GenericCamera
Method Name: async_camera_image


Project Name: home-assistant/home-assistant
Commit Name: 646c03eea1177bbe2944c9f73e22cfc5a1bac975
Time: 2017-10-30
Author: bachya1208@gmail.com
File Name: homeassistant/components/sensor/template.py
Class Name: SensorTemplate
Method Name: async_update


Project Name: home-assistant/home-assistant
Commit Name: 646c03eea1177bbe2944c9f73e22cfc5a1bac975
Time: 2017-10-30
Author: bachya1208@gmail.com
File Name: homeassistant/components/switch/template.py
Class Name: SwitchTemplate
Method Name: async_update