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

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

Loading…
Cancel
Save