0
我有一個簡單的websocket服務器在Python中使用龍捲風。它完美的工作,但我需要一個功能,我不知道如何實現。所以有一個websocket服務器在我的端口上偵聽。現在當這個服務器收到一條消息時,我需要符合這個消息切換操作並運行很長時間的任務或取消運行的任務(由此服務器運行的任務)。它應該是這樣的:Websockets,運行非常長的任務,並改變任務運行時的配置
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("Hello World")
def on_message(self, message):
#unpack message
command = message[:2]
taskid = message[2:4]
print 'some message'
if command == '00':
# starting task with id = 1 which will take over 1 hour or more
task.start() #it will take more than 1 hour!
elif command == '01':
# cancel task with id = 1
task.stop()
elif command == 'SomeOtherOptionsINeedToHandle':
# Do the others
task.internal_loop.change_configuration
def on_close(self):
print 'connection closed'
我有點困惑,我希望你能給我一些提示。謝謝。