From b9cc2c210f85f6b6a672b3f0be853e26fcfa9ae3 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 25 Jun 2019 11:15:43 -0700 Subject: [PATCH] Explain how we take care of servicer threads --- examples/python/cancellation/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/python/cancellation/README.md b/examples/python/cancellation/README.md index c50cc3b34df..7329ed834e8 100644 --- a/examples/python/cancellation/README.md +++ b/examples/python/cancellation/README.md @@ -153,6 +153,14 @@ In this example, we use the `ServicerContext.add_callback` method to set a down through our hashing algorithm and ensure to check that the RPC is still ongoing before each iteration. +```python +stop_event = threading.Event() +def on_rpc_done(): + # Regain servicer thread. + stop_event.set() +context.add_callback(on_rpc_done) +secret = _find_secret(stop_event) +``` ##### Initiating a Cancellation from a Servicer