From 7a90bda188c11a6ced8f692d993ad3b741df8e87 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 24 Mar 2022 13:45:26 +0100 Subject: [PATCH] [chiptest] Network-independent RPC server shutdown (#15954) Terminating app-register RPC server with the usage RPC call itself might cause troubles in case when the network connection is not reliable (e.g. no route to the server). This commit simplifies the shutdown process by using dedicated shutdown method. --- scripts/tests/chiptest/accessories.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/scripts/tests/chiptest/accessories.py b/scripts/tests/chiptest/accessories.py index b91a38f50c525b..44ae550b2f9b91 100644 --- a/scripts/tests/chiptest/accessories.py +++ b/scripts/tests/chiptest/accessories.py @@ -15,7 +15,6 @@ import sys import threading -from xmlrpc.client import ServerProxy from xmlrpc.server import SimpleXMLRPCServer IP = '127.0.0.1' @@ -98,9 +97,6 @@ def waitForOperationalAdvertisement(self, name): return accessory.waitForOperationalAdvertisement() return False - def ping(self): - return True - def __startXMLRPCServer(self): self.server = SimpleXMLRPCServer((IP, PORT)) @@ -114,20 +110,9 @@ def __startXMLRPCServer(self): self.server.register_function( self.waitForOperationalAdvertisement, 'waitForOperationalAdvertisement') - self.server.register_function(self.ping, 'ping') - self.server_thread = threading.Thread(target=self.__handle_request) + self.server_thread = threading.Thread(target=self.server.serve_forever) self.server_thread.start() - def __handle_request(self): - self.__should_handle_requests = True - while self.__should_handle_requests: - self.server.handle_request() - def __stopXMLRPCServer(self): - self.__should_handle_requests = False - # handle_request will wait until it receives a message, - # so let's send a ping to the server - client = ServerProxy('http://' + IP + ':' + - str(PORT) + '/', allow_none=True) - client.ping() + self.server.shutdown()