Skip to content

Commit 05337ba

Browse files
author
Barkin Simsek
committed
Always return an error while stopping subscriptions.
1 parent cc67090 commit 05337ba

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

python/mujinwebstackclient/controllerwebclientraw.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def Destroy(self):
199199
self.SetDestroy()
200200
if self._backgroundThread is not None:
201201
# make sure to stop subscriptions and close the websocket first
202-
self._backgroundThread.RunCoroutine(self._StopAllSubscriptions()).result()
202+
with self._subscriptionLock:
203+
self._backgroundThread.RunCoroutine(self._StopAllSubscriptions(ControllerGraphClientException(_('Shutting down')))).result()
203204
# next destroy the thread
204205
self._backgroundThread.Destroy()
205206
self._backgroundThread = None
@@ -488,13 +489,14 @@ async def _ListenToWebSocket(self):
488489
with self._subscriptionLock:
489490
await self._StopAllSubscriptions(ControllerGraphClientException(_('Failed to listen to WebSocket: %s') % (e)))
490491

491-
async def _StopAllSubscriptions(self, error: Optional[ControllerGraphClientException] = None):
492+
async def _StopAllSubscriptions(self, error: Optional[ControllerGraphClientException]):
493+
"""Needs to run under self._subscriptionLock
494+
"""
492495
# close the websocket
493496
await self._CloseWebSocket()
494497
# send a message back to the callers using the callback function and drop all subscriptions
495-
if error is not None:
496-
for subscriptionId, subscription in self._subscriptions.items():
497-
subscription.GetSubscriptionCallbackFunction()(error=error, response=None)
498+
for subscriptionId, subscription in self._subscriptions.items():
499+
subscription.GetSubscriptionCallbackFunction()(error=error, response=None)
498500
self._subscriptions.clear()
499501

500502
def SubscribeGraphAPI(self, query: str, callbackFunction: Callable[[Optional[str], Optional[dict]], None], variables: Optional[dict] = None) -> Subscription:

0 commit comments

Comments
 (0)