如何从 RequestHandler 到达 HTTPServer class?

How to get to HTTPServer class from RequestHandler?

我有 class 基于 HTTPServer:

class MyServer(tornado.httpserver.HTTPServer):

    def __init__(self, *args, **kwargs):
        super(MyServer, self).__init__(*args, **kwargs)

        self.my_prog = subprocess.Popen(
            ['python', 'myprog.py'],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE
        )

并查看:

class MessageHandler(tornado.web.RequestHandler):

    def get(self, some_data):

        # some stuff and
        # here I would like to get to 
        # MyServer.my_prog

我想通过通信消息从视图发送到 my_prog。怎么做?

HTTPServer 没有暴露给处理程序。你为什么继承 HTTPServer?它并不是真正为以这种方式进行定制而设计的。为此,更典型的做法是使用 Application 的子类(该 Application 可用于处理程序 self.application)。