I have a basic websocket server using Tornado framework in python. I want to share a value between the server functions:
class EchoWebSocket(websocket.WebSocketHandler):
def check_origin(self, origin):
return True
def open(self):
print ("connection opened")
def on_close(self):
tornado.ioloop.IOLoop.instance().stop()
print ("connection closed")
def on_message(self,message):
print (message)
def Main():
application = tornado.web.Application([(r"/", EchoWebSocket),])
application.listen(9000)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
Main()
I tried to create a global object from a class like this:
class operate:
state = "mutual"
def __init__(self):
self.state = 'mutual'
def play(self):
self.state = 'play'
def pause(self):
self.state = 'pause'
def getStatus(self):
return self.state
and call a global object, guessing that since the object is global it will be the same not creating a new one every message:
def open(self):
global objectTV
objectTV = operate()
objectTV.play()
.
.
.
.
def on_message(self,message):
global objectTV
objectTV = operate()
print(objectTV.getStatus())
But it always print 'mutual'?