Skip to content

Commit

Permalink
Merge pull request #196 from anecdata/exit
Browse files Browse the repository at this point in the history
Add context manager for socket
  • Loading branch information
dhalbert authored Mar 19, 2024
2 parents 4b33ddd + 57ade90 commit 956d6a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adafruit_esp32spi/adafruit_esp32spi_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ def __init__(

# pylint: enable=too-many-arguments

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self.close()
while (
_the_interface.socket_status(self._socknum)
!= adafruit_esp32spi.SOCKET_CLOSED
):
pass

def connect(self, address, conntype=None):
"""Connect the socket to the 'address' (which can be 32bit packed IP or
a hostname string). 'conntype' is an extra that may indicate SSL or not,
Expand Down

0 comments on commit 956d6a0

Please sign in to comment.