Your second post has a tiny typo I think. To pass a Python function as
parameter, you don't need the parentheses:

        context.add_callback(context.cancel)

Also, the callbacks added to the context will only execute after the gRPC
termination. By that time, the "context.cancel" will be a no-op.

About your first question regarding to deadline. The deadline exceeded in
client-side will cancel the server-side request, but it is not cancelled
automatically since there is no (legit) way in Python to terminate a
running thread. If you would like to terminate your server task, please
explicitly check the "is_active()" function in servicer context.

Hope this will answer your questions :)






On Tue, Mar 19, 2019 at 10:32 AM <[email protected]> wrote:

> In addition, it seems like the callback functionality should be able
> handle this through something like this ...
>
> Server pseudo-code:
>
>     def Server(self, request_iterator, context):
>         context.add_callback(context.cancel())
>         for request in request_iterator:
>             pass
>
>         for _ in range(10):
>             time.sleep(1)
>
>         print(context.is_active())
>         print('still running!')
>         return test_pb2.Response()
>
> ... however, this immediately cancels the RPC, which seems to disagree
> with the intended behavior described in the documentation:
> https://grpc.io/grpc/python/grpc.html#grpc.RpcContext.add_callback
>
> On Tuesday, March 19, 2019 at 9:48:53 AM UTC-7, [email protected]
> wrote:
>>
>> I want to verify some behavior in the Python code -- are timeouts only
>> respected while receiving requests and not after requests have been
>> received (but RPC is not finished)? Here's an example that uses a
>> client-streaming RPC:
>>
>> Server pseudo-code:
>>
>>     def Server(self, request_iterator, context):
>>         for request in request_iterator:
>>             pass
>>
>>         for _ in range(10):
>>             time.sleep(1)
>>
>>         print(context.is_active())
>>         print('still running!')
>>         return test_pb2.Response()
>>
>>
>> Client pseudo-code:
>>
>>     def yielder():
>>         for _ in range(20):
>>             yield test_pb2.Request()
>>
>>     stub = test_pb2_grpc.TestStub(channel)
>>     response = stub.Server(yielder(), timeout=5)
>>     print(response)
>>
>>
>> What happens is that the server will receive all the requests streams and
>> while performing an operation, the timeout will pass and context will be
>> inactive -- however, the RPC never aborts (i.e. the server will print
>> 'still running!'). Is this intended behavior? I would expect that the
>> server to stop processing after the timeout has elapsed.
>>
> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/a9d19d24-75d0-459f-ac51-c15a4d02422e%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/a9d19d24-75d0-459f-ac51-c15a4d02422e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAMC1%3Djd_T4rr8owP4tu23-30RZXsqYAd16b0a2UhK8T_o3%3D9tA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to