@@ -92,10 +92,7 @@ def _is_active(self):
92
92
# Note: there is a possibility that this starts *before* the call
93
93
# property is set. So we have to check if self.call is set before
94
94
# seeing if it's active.
95
- if self .call is not None and not self .call .is_active ():
96
- return False
97
- else :
98
- return True
95
+ return self .call is not None and self .call .is_active ()
99
96
100
97
def __iter__ (self ):
101
98
if self ._initial_request is not None :
@@ -265,6 +262,10 @@ def add_done_callback(self, callback):
265
262
self ._callbacks .append (callback )
266
263
267
264
def _on_call_done (self , future ):
265
+ # This occurs when the RPC errors or is successfully terminated.
266
+ # Note that grpc's "future" here can also be a grpc.RpcError.
267
+ # See note in https://github.com/grpc/grpc/issues/10885#issuecomment-302651331
268
+ # that `grpc.RpcError` is also `grpc.call`.
268
269
for callback in self ._callbacks :
269
270
callback (future )
270
271
@@ -276,7 +277,13 @@ def open(self):
276
277
request_generator = _RequestQueueGenerator (
277
278
self ._request_queue , initial_request = self ._initial_request
278
279
)
279
- call = self ._start_rpc (iter (request_generator ), metadata = self ._rpc_metadata )
280
+ try :
281
+ call = self ._start_rpc (iter (request_generator ), metadata = self ._rpc_metadata )
282
+ except exceptions .GoogleAPICallError as exc :
283
+ # The original `grpc.RpcError` (which is usually also a `grpc.Call`) is
284
+ # available from the ``response`` property on the mapped exception.
285
+ self ._on_call_done (exc .response )
286
+ raise
280
287
281
288
request_generator .call = call
282
289
0 commit comments