I have a module called foobar
and it contains a bunch of functions I would like to call remotely.
My current solution is to wrap all those functions as static methods in a class and share that.
Here's my code:
pyro_server.py:
import Pyro4
import foobar
import inspect
Pyro4.config.REQUIRE_EXPOSE = False
import my_custom_pyro_config as pyro_config
def module_to_class(module):
class Wrapper:
pass
for name, func in inspect.getmembers(module, inspect.isfunction):
setattr(Wrapper, name, staticmethod(func))
return Wrapper
def main():
name_server = Pyro4.locateNS(host=pyro_config.IP, port=pyro_config.NS_PORT)
daemon = Pyro4.Daemon(host=pyro_config.IP, port=pyro_config.PYRO_PORT)
foobar_uri = daemon.register(module_to_class(foobar))
name_server.register("foobar", foobar_uri)
print("Entering request loop")
daemon.requestLoop()
It works, but it feels kind of dodgy...
Is there a better way to do this? I'm open to switching to another RPC library