Handle non-iterator objects in consume_request_iterator

Restructure the consume_request_iterator method to handle exceptions
where the object being passed is not an iterator. Fixes #8231 and #8454.
pull/8686/head
siddharthshukla 8 years ago
parent ab8fb5be32
commit 6bfa91a795
  1. 12
      src/python/grpcio/grpc/_channel.py

@ -32,6 +32,7 @@
import sys
import threading
import time
import logging
import grpc
from grpc import _common
@ -197,7 +198,16 @@ def _consume_request_iterator(
event_handler = _event_handler(state, call, None)
def consume_request_iterator():
for request in request_iterator:
while True:
try:
request = next(request_iterator)
except StopIteration:
break
except Exception as e:
logging.exception("Exception iterating requests!")
call.cancel()
_abort(state, grpc.StatusCode.UNKNOWN, "Exception iterating requests!")
return
serialized_request = _common.serialize(request, request_serializer)
with state.condition:
if state.code is None and not state.cancelled:

Loading…
Cancel
Save