停止龙卷风应用程序 [英] Stopping a tornado application

查看:25
本文介绍了停止龙卷风应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们以 Tornado 主页中的 hello world 应用程序为例:

Let's take the hello world application in the Tornado home page:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
  def get(self):
    self.write("Hello, world")

application = tornado.web.Application([
  (r"/", MainHandler),
])

if __name__ == "__main__":
  application.listen(8888)
  tornado.ioloop.IOLoop.instance().start()

有没有办法在 IOloop 启动后而不停止它,基本上停止应用程序并启动另一个应用程序(在同一端口或另一个端口上)?

Is there a way, after the IOloop has been started and without stopping it, to essentially stop the application and start another one (on the same port or on another)?

我看到我可以在运行时添加新应用程序(侦听不同端口),但我不知道如何停止现有应用程序.

I saw that I can add new application (listening on different ports) at runtime, but I do not know how I could stop existing ones.

推荐答案

Application.listen() 方法实际上创建了一个 HTTPServer 并调用它的 listen() 方法.HTTPServer 对象具有 stop() 方法,这可能是您所需要的.但是为了做到这一点,您必须在脚本中显式创建 HTTPServer 对象.

Application.listen() method actually creates a HTTPServer and calls its listen() medthod. HTTPServer objects has stop() method which is probably what you need. But in order to do it you have to explicitly create HTTPServer object in your script.

server = HTTPServer(application)
server.listen(8888)
tornado.ioloop.IOLoop.instance().start()

#somewhere in your code
server.stop()

这篇关于停止龙卷风应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆