1# gRPC Python Non-Blocking Streaming RPC Client Example 2 3The goal of this example is to demonstrate how to handle streaming responses 4without blocking the current thread. Effectively, this can be achieved by 5converting the gRPC Python streaming API into callback-based. 6 7In this example, the RPC service `Phone` simulates the life cycle of virtual 8phone calls. It requires one thread to handle the phone-call session state 9changes, and another thread to process the audio stream. In this case, the 10normal blocking style API could not fulfill the need easily. Hence, we should 11asynchronously execute the streaming RPC. 12 13## Steps to run this example 14 15Start the server in one session 16``` 17python3 server.py 18``` 19 20Start the client in another session 21``` 22python3 client.py 23``` 24 25## Example Output 26``` 27$ python3 server.py 28INFO:root:Server serving at [::]:50051 29INFO:root:Received a phone call request for number [1415926535] 30INFO:root:Created a call session [{ 31 "sessionId": "0", 32 "media": "https://link.to.audio.resources" 33}] 34INFO:root:Call finished [1415926535] 35INFO:root:Call session cleaned [{ 36 "sessionId": "0", 37 "media": "https://link.to.audio.resources" 38}] 39``` 40 41``` 42$ python3 client.py 43INFO:root:Waiting for peer to connect [1415926535]... 44INFO:root:Call toward [1415926535] enters [NEW] state 45INFO:root:Call toward [1415926535] enters [ACTIVE] state 46INFO:root:Consuming audio resource [https://link.to.audio.resources] 47INFO:root:Call toward [1415926535] enters [ENDED] state 48INFO:root:Audio session finished [https://link.to.audio.resources] 49INFO:root:Call finished! 50``` 51