Advertisement
asees

Server.py

Jan 19th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import rpyc
  2. import threading
  3. from threading import RLock
  4. test = ['hi']
  5. myReferences= set()
  6. myReferencesLock = RLock()
  7. class MyService(rpyc.Service):
  8.  
  9. def on_connect(self):
  10. """Think o+ this as a constructor of the class, but with
  11. a new name so not to 'overload' the parent's init"""
  12. self.fn = None
  13.  
  14. def exposed_serverPrint(self,message):
  15. global test
  16. test.append(message)
  17. print message +" joined the room"
  18.  
  19. def exposed_serverPrintMessage(self,message):
  20. for i in myReferences:
  21. if i is not self.fn:
  22. i(message)
  23.  
  24.  
  25.  
  26. def exposed_setCallback(self,fn):
  27. global myReferences
  28. # i = 0
  29. self.fn = fn # Saves the remote function for calling later
  30. print self.fn
  31. with myReferencesLock:
  32. myReferences.add(self.fn)
  33. print myReferences
  34. for x in myReferences:
  35. print x
  36. #print abc
  37.  
  38.  
  39.  
  40. if __name__ == "__main__":
  41. # lists are pass by reference, so the same 'test'
  42. # will be available to all threads
  43. # While not required, think about locking!
  44. from rpyc.utils.server import ThreadedServer
  45. t = ThreadedServer(MyService, port = 18888)
  46. t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement