| 1 |
# Retry Example in gRPC Python |
| 2 |
|
| 3 |
## Prerequisite |
| 4 |
|
| 5 |
* grpcio >= 1.39.0 |
| 6 |
* grpcio-tools >= 1.39.0 |
| 7 |
|
| 8 |
## Running the example |
| 9 |
|
| 10 |
In terminal 1, start the flaky server: |
| 11 |
|
| 12 |
```sh |
| 13 |
python3 flaky_server.py |
| 14 |
``` |
| 15 |
|
| 16 |
In terminal 2, start the retry clients: |
| 17 |
|
| 18 |
```sh |
| 19 |
python3 retry_client.py |
| 20 |
# Or |
| 21 |
python3 async_retry_client.py |
| 22 |
``` |
| 23 |
|
| 24 |
## Expect results |
| 25 |
|
| 26 |
The client RPC will succeed, even with server injecting multiple errors. Here is an example server log: |
| 27 |
|
| 28 |
```sh |
| 29 |
$ python3 flaky_server.py |
| 30 |
INFO:root:Starting flaky server on [::]:50051 |
| 31 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54471 |
| 32 |
INFO:root:Successfully responding to RPC from ipv6:[::1]:54473 |
| 33 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54491 |
| 34 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54581 |
| 35 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54581 |
| 36 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54581 |
| 37 |
INFO:root:Injecting error to RPC from ipv6:[::1]:54581 |
| 38 |
INFO:root:Successfully responding to RPC from ipv6:[::1]:54581 |
| 39 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55474 |
| 40 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55474 |
| 41 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55474 |
| 42 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55474 |
| 43 |
INFO:root:Successfully responding to RPC from ipv6:[::1]:55474 |
| 44 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55533 |
| 45 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55533 |
| 46 |
INFO:root:Injecting error to RPC from ipv6:[::1]:55533 |
| 47 |
INFO:root:Successfully responding to RPC from ipv6:[::1]:55533 |
| 48 |
``` |