From 191e250827a54d15abc9f7a5586318a29728d1b0 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Tue, 14 Aug 2018 10:05:56 -0700 Subject: mpm: reset the RPC server upon reload When reloading the Periph Manager (as when we run the image loader), we need to run the RPCServer `__init__` function in order to reset the cache of RPC methods. Otherwise, that cache keeps stale references to old functions (and prevents garbage collection). It may be possible to reset the method cache some other way, but the `_methods` attribute of RPCServer is Cython, and doesn't seem to be accessible in our Python code. --- mpm/python/usrp_mpm/rpc_server.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/rpc_server.py b/mpm/python/usrp_mpm/rpc_server.py index 29ad3daa8..35202efa9 100644 --- a/mpm/python/usrp_mpm/rpc_server.py +++ b/mpm/python/usrp_mpm/rpc_server.py @@ -457,6 +457,16 @@ class MPMServer(RPCServer): self.periph_manager = None self.periph_manager = self._mgr_generator() self._init_rpc_calls(self.periph_manager) + # RPCServer caches RPC methods, but that cache is not accessible here + # (because Cython). Re-running `RPCServer.__init__` clears that cache, + # and allows us to register new RPC methods (which we need to do because + # we're resetting the PeriphManager). + # A note on maintenance: This has been deemed safe through inspection of + # the RPCServer source code. However, this is not typical Python, and + # changes in future versions of RPCServer may cause issues. + super(MPMServer, self).__init__( + pack_params={'use_bin_type': True}, + ) def update_component(self, token, file_metadata_l, data_l): """" -- cgit v1.2.3