Skip to content

Commit 6a0d38c

Browse files
committed
chore: fix the mutual exclusion cancel() call
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 46468ef commit 6a0d38c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/hiero_sdk_python/utils/subscription_handle.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ def __init__(self):
1919

2020
def _set_call(self, call: Any):
2121
"""Sets the active gRPC call so it can be cancelled."""
22+
should_cancel = False
23+
2224
with self._lock:
2325
self._call = call
2426

25-
if self._cancelled.is_set():
26-
self._call.cancel()
27+
if call is not None and self._cancelled.is_set():
28+
should_cancel = True
29+
30+
if should_cancel:
31+
self._call.cancel()
2732

2833
def cancel(self):
2934
"""Signals to cancel the subscription."""
35+
should_cancel = False
36+
3037
with self._lock:
3138
self._cancelled.set()
3239

33-
if self._call:
34-
self._call.cancel()
40+
if self._call is not None:
41+
should_cancel = True
42+
43+
if should_cancel:
44+
self._call.cancel()
3545

3646
def is_cancelled(self) -> bool:
3747
"""Returns True if this subscription is already cancelled."""

0 commit comments

Comments
 (0)