Answer the question
In order to leave comments, you need to log in
How to make "long" events in Python Tornado?
I'll explain with an example. I am writing a TCP proxy server for one game, it not only processes packets, but also sends various requests on behalf of the game to collect statistics, sometimes it answers itself instead of the game. The bottom line is that it all grew so much that I decided to make a simple plugin system and break all the message processing logic into many plugins.
Then a typical plugin, if simplified, starts to look like this:
class SimplePlugin:
@coroutine
def on_request_from_client(self, event):
чё-то делаем с запросом
@coroutine
def on_response_from_server(self, event):
чё-то делаем с ответом
class SimplePlugin:
@coroutine
def on_request_from_client(self, event):
чё-то делаем с запросом
yield event.wait_for_response()
чё-то делаем с ответом
class SimplePlugin:
@coroutine
def on_request_from_client(self, event):
чё-то делаем с запросом
def callback():
чё-то делаем с ответом
IOLoop.add_future(event.response_future, callback)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question