pychromecast
pychromecast copied to clipboard
socket loop breaks when application launch raise exception (via callback)
When exception occurs in callback function, it breaks the socket_client run() loop. I got the case when using media.block_until_active() when running a new application. Exception is raised by _block_till_launched function of socket_client
Error is coming from the cast device for whatever reason (application specific?) so should not break the socket loop but should be managed via the existing launch error listener (register_launch_error_listener)
# line 398 - socket_client.py
# existing code
if REQUEST_ID in data:
callback = self._request_callbacks.pop(data[REQUEST_ID], None)
if callback is not None:
event = callback['event']
callback['response'] = data
function = callback['function']
event.set()
if function:
function(data)
# proposition
if REQUEST_ID in data:
callback = self._request_callbacks.pop(data[REQUEST_ID], None)
if callback is not None:
event = callback['event']
callback['response'] = data
function = callback['function']
event.set()
if function:
try:
function(data)
except Exception as e :
self.logger.error("runonce: Error calling callback : %s" % str(e))
# just log and do nothing else to keep the loop running....
Pull request with proposal : pull request #244