@@ -624,17 +624,15 @@ def on_response(response):
624
624
``open()``ed yet.
625
625
on_response (Callable[[protobuf.Message], None]): The callback to
626
626
be called for every response on the stream.
627
- reraise_exceptions (bool): Whether to reraise exceptions during
628
- the lifetime of the consumer, generally those that are not
629
- handled by `BidiRpc`'s `should_recover` or `should_terminate`.
630
- Default `False`.
627
+ on_fatal_exception (Callable[[Exception], None]): The callback to
628
+ be called on fatal errors during consumption. Default None.
631
629
"""
632
630
633
- def __init__ (self , bidi_rpc , on_response , reraise_exceptions = False ):
631
+ def __init__ (self , bidi_rpc , on_response , on_fatal_exception = None ):
634
632
self ._bidi_rpc = bidi_rpc
635
633
self ._on_response = on_response
636
634
self ._paused = False
637
- self ._reraise_exceptions = reraise_exceptions
635
+ self ._on_fatal_exception = on_fatal_exception
638
636
self ._wake = threading .Condition ()
639
637
self ._thread = None
640
638
self ._operational_lock = threading .Lock ()
@@ -681,17 +679,17 @@ def _thread_main(self, ready):
681
679
exc ,
682
680
exc_info = True ,
683
681
)
684
- if self ._reraise_exceptions :
685
- raise
682
+ if self ._on_fatal_exception is not None :
683
+ self . _on_fatal_exception ( exc )
686
684
687
685
except Exception as exc :
688
686
_LOGGER .exception (
689
687
"%s caught unexpected exception %s and will exit." ,
690
688
_BIDIRECTIONAL_CONSUMER_NAME ,
691
689
exc ,
692
690
)
693
- if self ._reraise_exceptions :
694
- raise
691
+ if self ._on_fatal_exception is not None :
692
+ self . _on_fatal_exception ( exc )
695
693
696
694
_LOGGER .info ("%s exiting" , _BIDIRECTIONAL_CONSUMER_NAME )
697
695
@@ -734,6 +732,7 @@ def stop(self):
734
732
735
733
self ._thread = None
736
734
self ._on_response = None
735
+ self ._on_fatal_exception = None
737
736
738
737
@property
739
738
def is_active (self ):
0 commit comments