Skip to content

Commit

Permalink
Fix race in SocketClient.send_message (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored and balloob committed Jul 13, 2017
1 parent a867ac9 commit 819ccb6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,20 +582,20 @@ def send_message(self, destination_id, namespace, data,
raise PyChromecastStopped("Socket client's thread is stopped.")
if not self.connecting and not self._force_recon:
try:
if not no_add_request_id and callback_function:
self._request_callbacks[request_id] = {
'event': threading.Event(),
'response': None,
'function': callback_function,
}
self.socket.sendall(be_size + msg.SerializeToString())
except socket.error:
del self._request_callbacks[request_id]
self._force_recon = True
self.logger.info('Error writing to socket.')
else:
raise NotConnected("Chromecast is connecting...")

if not no_add_request_id and callback_function:
self._request_callbacks[request_id] = {
'event': threading.Event(),
'response': None,
'function': callback_function,
}

def send_platform_message(self, namespace, message, inc_session_id=False,
callback_function_param=False):
""" Helper method to send a message to the platform. """
Expand Down

0 comments on commit 819ccb6

Please sign in to comment.