Optimize the logic & add comments

pull/21988/head
Lidi Zheng 5 years ago
parent 2789f83f85
commit 5a29f33a25
  1. 10
      src/python/grpcio/grpc/experimental/aio/_channel.py
  2. 1
      src/python/grpcio_tests/tests_aio/unit/close_channel_test.py

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Invocation-side implementation of gRPC Asyncio Python."""
import asyncio
import sys
from typing import Any, AsyncIterable, Iterable, Optional, Sequence
@ -357,14 +358,17 @@ class Channel:
call_tasks = []
for task in tasks:
stack = task.get_stack(limit=1)
# If the Task is created by a C-extension, the stack will be empty.
if not stack:
continue
# Locate ones created by `aio.Call`.
frame = stack[0]
if 'self' in frame.f_locals:
if isinstance(frame.f_locals['self'], _base_call.Call):
calls.append(frame.f_locals['self'])
candidate = frame.f_locals.get('self')
if candidate:
if isinstance(candidate, _base_call.Call):
calls.append(candidate)
call_tasks.append(task)
# If needed, try to wait for them to finish.

@ -16,7 +16,6 @@
import asyncio
import logging
import unittest
from weakref import WeakSet
import grpc
from grpc.experimental import aio

Loading…
Cancel
Save