Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import rpyc
- import threading
- from threading import RLock
- test = ['hi']
- myReferences= set()
- myReferencesLock = RLock()
- class MyService(rpyc.Service):
- def on_connect(self):
- """Think o+ this as a constructor of the class, but with
- a new name so not to 'overload' the parent's init"""
- self.fn = None
- def exposed_serverPrint(self,message):
- global test
- test.append(message)
- print message +" joined the room"
- def exposed_serverPrintMessage(self,message):
- for i in myReferences:
- if i is not self.fn:
- i(message)
- def exposed_setCallback(self,fn):
- global myReferences
- # i = 0
- self.fn = fn # Saves the remote function for calling later
- print self.fn
- with myReferencesLock:
- myReferences.add(self.fn)
- print myReferences
- for x in myReferences:
- print x
- #print abc
- if __name__ == "__main__":
- # lists are pass by reference, so the same 'test'
- # will be available to all threads
- # While not required, think about locking!
- from rpyc.utils.server import ThreadedServer
- t = ThreadedServer(MyService, port = 18888)
- t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement