Skip to content

Commit

Permalink
[chiptest] Network-independent RPC server shutdown (#15954)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arkq authored Mar 24, 2022
1 parent be4abbe commit 7a90bda
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions scripts/tests/chiptest/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import sys
import threading
from xmlrpc.client import ServerProxy
from xmlrpc.server import SimpleXMLRPCServer

IP = '127.0.0.1'
Expand Down Expand Up @@ -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))

Expand All @@ -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()

0 comments on commit 7a90bda

Please sign in to comment.