Registers a handler to invoke when a response is received for this request. The handler is invoked with Response as its sole argument. If response has already been received, invokes the handler immediately. It is guaranteed that self.response is set before the handler is in
(self, response_handler)
| 783 | return self.response.body |
| 784 | |
| 785 | def on_response(self, response_handler): |
| 786 | """Registers a handler to invoke when a response is received for this request. |
| 787 | The handler is invoked with Response as its sole argument. |
| 788 | |
| 789 | If response has already been received, invokes the handler immediately. |
| 790 | |
| 791 | It is guaranteed that self.response is set before the handler is invoked. |
| 792 | If no response was received from the other party before the channel closed, |
| 793 | self.response is a dummy Response with body=NoMoreMessages(). |
| 794 | |
| 795 | The handler is always invoked asynchronously on an unspecified background |
| 796 | thread - thus, the caller of on_response() can never be blocked or deadlocked |
| 797 | by the handler. |
| 798 | |
| 799 | No further incoming messages are processed until the handler returns, except for |
| 800 | responses to requests that have wait_for_response() invoked on them. |
| 801 | """ |
| 802 | |
| 803 | with self.channel: |
| 804 | self._response_handlers.append(response_handler) |
| 805 | self._enqueue_response_handlers() |
| 806 | |
| 807 | def _enqueue_response_handlers(self): |
| 808 | response = self.response |