Skip to content

Please use with to ensure resource is de-allocated #100

Closed
@jepler

Description

@jepler

In get, post, etc., the logic is similar to the following:

    def _get(self, path):
        """
        GET data from Adafruit IO

        :param str path: Formatted Adafruit IO URL from _compose_path
        """
        response = self._http.get(
            path, headers=self._create_headers(self._aio_headers[1])
        )
        self._handle_error(response)
        json_data = response.json()
        response.close()
        return json_data

Note that in the case that self._handle_error() throws, the response is not closed.

By using with ... as response:, the response will be automatically closed. The explicit response.close() call can probably be removed too.

I raise this issue because @kattni in discord mentioned encountering an espidf.MemoryError while using Adafruit IO_HTTP to retrieve the current time. However, I don't know if this is actually the cause of her problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions