The Tornado web descriptor, self.close () closes the connection without invoking the on_close () method

im new at (python, stackoverflow, tornado), so please be patient :). Correct me.

Im working with a tornado in a real time application. When I call self.close () inside the Websocket handler class, the on_close method does not start, since this time I made a small shell, fixed the problem and (for example) dropped the associated agent (pure avascript wss api client) correctly.

All network problems are thrown away since my bad shell works well and im in LAN environment.

Does anyone have the same problem? I can’t sleep without an explanation.

THANKS really.

## imports and other stuff 

AGENTS = set()     

class BackofficeWSSRailMain(tornado.websocket.WebSocketHandler):   

     def on_open(self):                  
       pass

     def on_message(self,raw_message):
       json_msg=json.loads(raw_message)
       login = function_that_process_login(json_msg)

       if login == True:
          AGENTS.add(self)
          self.write_message("ok")         
       else:
          self.write_message("nologin")
          self.close()         ### this part should fireup 
                               ### the on_close method but nothing 
                               ### happens so AGENT is not discarded.
                               ### here is when i actually call on_close_wrapper(),
                               ### the method below. 

     def on_close_wrapper(self):

       self.close()            ### this is my actual solution , 
                               ### waiting for more research.
       self.on_close()

     def on_close(self):      

       AGENTS.discard(self)

   ## Calling ioloop ...
+3
source share
2 answers

self.on_close , websocket. : -, Javascript, , , on_close . on_close , self.close .

- ; , self.close, .

+6

Source: https://habr.com/ru/post/1687209/


All Articles