Fix exception when attempting to select on a closed socket

This commit is contained in:
Charles Haley 2012-08-01 18:05:06 +02:00
parent 656a28986e
commit 11731fd030

View File

@ -447,18 +447,18 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
if self.is_connected: if self.is_connected:
self.noop_counter += 1 self.noop_counter += 1
if only_presence and (self.noop_counter % 5) != 1: if only_presence and (self.noop_counter % 5) != 1:
ans = select.select((self.device_socket,), (), (), 0) try:
if len(ans[0]) == 0: ans = select.select((self.device_socket,), (), (), 0)
return (True, self) if len(ans[0]) == 0:
# The socket indicates that something is there. Given the return (True, self)
# protocol, this can only be a disconnect notification. Fall # The socket indicates that something is there. Given the
# through and actually try to talk to the client. # protocol, this can only be a disconnect notification. Fall
try: # through and actually try to talk to the client.
# This will usually toss an exception if the socket is gone. # This will usually toss an exception if the socket is gone.
if self._call_client('NOOP', dict())[0] is None: if self._call_client('NOOP', dict())[0] is None:
self.is_connected = False
except:
self.is_connected = False self.is_connected = False
except:
self.is_connected = False
if not self.is_connected: if not self.is_connected:
self.device_socket.close() self.device_socket.close()
return (self.is_connected, self) return (self.is_connected, self)