Global Object in Pyro

101 views Asked by At

I want to export a function via RPC. Therefore I use Pyro4 for Python. This works so far. Now I want that function to work also on the data the belong to the RPC-Server. Is this possible? If so, how?

#!/usr/bin/env python3
import Pyro4
import myrpcstuff
listIwantToWorkWith=["apples","bananas","oranges"]
rcpthing=myrpcstuff.myrpcFunction()
daemon=Pyro4.Daemon()
uri=daemon.register(rpcthing)
daemon.requestLoop()

What do I have to write in myrpcstuff.myrpcFunction() to access listIwantToWorkWith, or do I have to mark the list global?

1

There are 1 answers

0
Irmen de Jong On

This isn't a Pyro specific question; the question is a general Python question about how to share data between functions or modules.

Pass the data you want to work on, to the objects that you want to have access to the data. You can do this via parameters or perhaps by creating a custom class and pass it the data via its init. This is all basic Python.

If you want to stay within the Pyro realm though, perhaps have a look at the examples that come with it, to see how you can do certain things?