How do I maintain different sessions or local state with my zerorpc server?
For example (below), if I have a multiple clients, subsequent clients will overwrite the model state. I thought about each client having an ID, and the RPC logic will try to separate the variables that way, but tbis seems messy and how would I clear out old states/variables once the clients disconnect?
Server
import zerorpc
import FileLoader
class MyRPC(object):
def load(self, myFile):
self.model = FileLoader.load(myFile)
def getModelName(self):
return self.model.name
s = zerorpc.Server(MyRPC())
s.bind("tcp://0.0.0.0:4242")
s.run()
Client 1
import zerorpc
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
c.load("file1")
print c.getModelName()
Client 2
import zerorpc
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
c.load("file2") # AAAHH! The previously loaded model gets overwritten here!
print c.getModelName()
Not sure about sessions...but if you want to get back different models? Maybe you could just have once function that instantiates a new Model()?
Client: