Skip to content

Commit e96a409

Browse files
committed
update doc strings
1 parent 5464dc5 commit e96a409

File tree

2 files changed

+38
-53
lines changed

2 files changed

+38
-53
lines changed

google/api_core/bidi_async.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,44 @@
2626
class _AsyncRequestQueueGenerator:
2727
"""An async helper for sending requests to a gRPC stream from a Queue.
2828
29-
This generator takes requests off a given queue and yields them to gRPC.
30-
31-
This helper is useful when you have an indeterminate, indefinite, or
32-
otherwise open-ended set of requests to send through a request-streaming
33-
(or bidirectional) RPC.
34-
35-
The reason this is necessary is because gRPC takes an async iterator as the
36-
request for request-streaming RPCs. gRPC consumes this iterator to allow
37-
it to block while generating requests for the stream. However, if the
38-
generator blocks indefinitely gRPC will not be able to clean up the task
39-
as it'll be blocked on `anext(iterator)` and not be able to check the
40-
channel status to stop iterating. This helper mitigates that by waiting
41-
on the queue with a timeout and checking the RPC state before yielding.
42-
43-
Finally, it allows for retrying without swapping queues because if it does
44-
pull an item off the queue when the RPC is inactive, it'll immediately put
45-
it back and then exit. This is necessary because yielding the item in this
46-
case will cause gRPC to discard it. In practice, this means that the order
29+
This generator takes requests off a given queue and yields them to gRPC.
30+
31+
This helper is useful when you have an indeterminate, indefinite, or
32+
otherwise open-ended set of requests to send through a request-streaming
33+
(or bidirectional) RPC.
34+
35+
The reason this is necessary
36+
37+
is because it's let's user have control on the when they would want to
38+
send requests proto messages instead of sending all of them initilally.
39+
40+
This is achieved via asynchronous queue (asyncio.Queue),
41+
gRPC awaits until there's a message in the queue.
42+
43+
Finally, it allows for retrying without swapping queues because if it does
44+
pull an item off the queue when the RPC is inactive, it'll immediately put
45+
it back and then exit. This is necessary because yielding the item in this
46+
case will cause gRPC to discard it. In practice, this means that the order
4747
of messages is not guaranteed. If such a thing is necessary it would be
48-
easy to use a priority queue.
48+
easy to use a priority queue.
4949
50-
Example::
50+
Example::
5151
52-
requests = _AsyncRequestQueueGenerator(q)
53-
call = await stub.StreamingRequest(requests)
54-
requests.call = call
52+
requests = _AsyncRequestQueueGenerator(q)
53+
call = await stub.StreamingRequest(requests)
54+
requests.call = call
5555
56-
async for response in call:
57-
print(response)
58-
await q.put(...)
56+
async for response in call:
57+
print(response)
58+
await q.put(...)
5959
60-
Args:
61-
queue (asyncio.Queue): The request queue.
62-
initial_request (Union[protobuf.Message,
63-
Callable[[], protobuf.Message]]): The initial request to
64-
yield. This is done independently of the request queue to allow for
65-
easily restarting streams that require some initial configuration
66-
request.
60+
Args:
61+
queue (asyncio.Queue): The request queue.
62+
initial_request (Union[protobuf.Message,
63+
Callable[[], protobuf.Message]]): The initial request to
64+
yield. This is done independently of the request queue to allow for
65+
easily restarting streams that require some initial configuration
66+
request.
6767
"""
6868

6969
def __init__(self, queue: asyncio.Queue, initial_request=None):

google/api_core/bidi_base.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
"""Base class for Bi-directional streaming RPC helpers."""
13+
"""Base class for bi-directional streaming RPC helpers."""
1414

1515

1616
class BidiRpcBase:
17-
"""A base helper for consuming a bi-directional streaming RPC.
17+
"""A base class for consuming a bi-directional streaming RPC.
1818
1919
This maps gRPC's built-in interface which uses a request iterator and a
2020
response iterator into a socket-like :func:`send` and :func:`recv`. This
@@ -25,8 +25,9 @@ class BidiRpcBase:
2525
This does *not* retry the stream on errors.
2626
2727
Args:
28-
start_rpc (grpc.StreamStreamMultiCallable): The gRPC method used to
29-
start the RPC.
28+
start_rpc (Union[grpc.StreamStreamMultiCallable,
29+
grpc.aio.StreamStreamMultiCallable]): The gRPC method used
30+
to start the RPC.
3031
initial_request (Union[protobuf.Message,
3132
Callable[[], protobuf.Message]]): The initial request to
3233
yield. This is useful if an initial request is needed to start the
@@ -68,22 +69,6 @@ def _on_call_done(self, future):
6869
for callback in self._callbacks:
6970
callback(future)
7071

71-
# def open(self):
72-
# """Opens the stream."""
73-
# raise NotImplementedError("Not implemented in base class")
74-
75-
# def close(self):
76-
# """Closes the stream."""
77-
# raise NotImplementedError("Not implemented in base class")
78-
79-
# def send(self, request):
80-
# """Queue a message to be sent on the stream."""
81-
# raise NotImplementedError("Not implemented in base class")
82-
83-
# def recv(self):
84-
# """Wait for a message to be returned from the stream."""
85-
# raise NotImplementedError("Not implemented in base class")
86-
8772
@property
8873
def is_active(self):
8974
"""bool: True if this stream is currently open and active."""

0 commit comments

Comments
 (0)