Avoid shutdown delays when emulated_hue is enabled (#38472)

We would have to wait for the select to timeout for
emulated_hue upnp thread to shutdown

We now close the socket so the select unblocks
right away
This commit is contained in:
J. Nick Koston 2020-08-02 08:32:07 -10:00 committed by GitHub
parent 34b911203c
commit 03a0114e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,11 +74,14 @@ class UPNPResponderThread(threading.Thread):
self.upnp_bind_multicast = upnp_bind_multicast
self.advertise_ip = advertise_ip
self.advertise_port = advertise_port
self._ssdp_socket = None
def run(self):
"""Run the server."""
# Listen for UDP port 1900 packets sent to SSDP multicast address
ssdp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._ssdp_socket = ssdp_socket = socket.socket(
socket.AF_INET, socket.SOCK_DGRAM
)
ssdp_socket.setblocking(False)
# Required for receiving multicast
@ -101,7 +104,6 @@ class UPNPResponderThread(threading.Thread):
while True:
if self._interrupted:
clean_socket_close(ssdp_socket)
return
try:
@ -114,7 +116,6 @@ class UPNPResponderThread(threading.Thread):
continue
except OSError as ex:
if self._interrupted:
clean_socket_close(ssdp_socket)
return
_LOGGER.error(
@ -138,6 +139,8 @@ class UPNPResponderThread(threading.Thread):
"""Stop the server."""
# Request for server
self._interrupted = True
if self._ssdp_socket:
clean_socket_close(self._ssdp_socket)
self.join()
def _handle_request(self, data):