Open PaulAnnekov opened 5 years ago
XiaomiGatewayDiscovery.listen() and XiaomiGatewayDiscovery.stop_listen() look like shouldn't be called multiple times, because listen() sets self._mcastsocket (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L143) property and calling it for the 2nd time will overwrite this property. But from the other side there is a self._threads.append(thread) (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L146) call inside listen() which appends newly created thread to a thread pool. What's going on in these methods?
XiaomiGatewayDiscovery.listen()
XiaomiGatewayDiscovery.stop_listen()
listen()
self._mcastsocket
self._threads.append(thread)
Also, stop_listen() will never end, because thread.join() (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L165) waits until a thread will stop execution, but data, (ip_add, _) = self._mcastsocket.recvfrom(self.SOCKET_BUFSIZE) (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L171) inside thread is blocking. Thread won't stop until something will arrive to this socket and we will go out of the loop.
stop_listen()
thread.join()
data, (ip_add, _) = self._mcastsocket.recvfrom(self.SOCKET_BUFSIZE)
Anything was fixed with that?
XiaomiGatewayDiscovery.listen()
andXiaomiGatewayDiscovery.stop_listen()
look like shouldn't be called multiple times, becauselisten()
setsself._mcastsocket
(https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L143) property and calling it for the 2nd time will overwrite this property. But from the other side there is aself._threads.append(thread)
(https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L146) call insidelisten()
which appends newly created thread to a thread pool. What's going on in these methods?Also,
stop_listen()
will never end, becausethread.join()
(https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L165) waits until a thread will stop execution, butdata, (ip_add, _) = self._mcastsocket.recvfrom(self.SOCKET_BUFSIZE)
(https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L171) inside thread is blocking. Thread won't stop until something will arrive to this socket and we will go out of the loop.