Skip to content

Commit 956d6a0

Browse files
authored
Merge pull request #196 from anecdata/exit
Add context manager for socket
2 parents 4b33ddd + 57ade90 commit 956d6a0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

+11
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ def __init__(
6666

6767
# pylint: enable=too-many-arguments
6868

69+
def __enter__(self):
70+
return self
71+
72+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
73+
self.close()
74+
while (
75+
_the_interface.socket_status(self._socknum)
76+
!= adafruit_esp32spi.SOCKET_CLOSED
77+
):
78+
pass
79+
6980
def connect(self, address, conntype=None):
7081
"""Connect the socket to the 'address' (which can be 32bit packed IP or
7182
a hostname string). 'conntype' is an extra that may indicate SSL or not,

0 commit comments

Comments
 (0)