Skip to content

Commit

Permalink
Merge pull request #142 from AscendedEntity/patch-1
Browse files Browse the repository at this point in the history
Add error propagation from child thread to main thread
  • Loading branch information
akarneliuk authored Dec 20, 2023
2 parents ef224a6 + 056df83 commit 1c0cccf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,18 @@ def __init__(self, channel, request, metadata, once: bool = False):
# start the subscription in a separate thread
_client_stream = self._create_client_stream(request)

# Initialize error attribute to None. Used to catch errors in _subscribe_thread.
self.error = None

def enqueue_updates():
stub = gNMIStub(channel)
subscription = stub.Subscribe(_client_stream, metadata=metadata)
for update in subscription:
self._updates.put(update)
try:
stub = gNMIStub(channel)
subscription = stub.Subscribe(_client_stream, metadata=metadata)
for update in subscription:
self._updates.put(update)
except Exception as error:
self.error = error
raise error

self._subscribe_thread = threading.Thread(target=enqueue_updates)
self._subscribe_thread.start()
Expand Down

0 comments on commit 1c0cccf

Please sign in to comment.