如何从RequestHandler获取HTTPServer类?

时间:2015-03-07 23:00:51

标签: tornado

我有基于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。怎么做?

1 个答案:

答案 0 :(得分:1)

HTTPServer不向处理程序公开。你为什么要继承HTTPServer?它不是真的以这种方式设计用于定制。为此目的使用Application的子类更为典型(应用程序可以作为self.application处理程序使用。)