本文介绍了Tornado Python作为守护程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是用龙卷风编写的,我想使其像apache或nginx一样正常工作,

I have my code written with tornado and I want to make it work pretty much like apache or nginx, that is

  1. 即使我关闭外壳,它也必须继续监听端口.
  2. 它必须在系统重新启动时自动启动

即使关闭外壳,我也尝试过nohup命令使其正常工作.有用.但是我想知道是否有更清洁的选择可用于相同的选择?

I have tried nohup command to make it work even when I close the shell. It works. But I am wondering if there is a cleaner option available for the same?

推荐答案

来自官方文档这里.

大多数Tornado应用程序都作为单个进程运行.对于生产而言,这通常意味着外部流程管理和代理的直接组合.这里是一些最佳实践/资源.

Most Tornado apps are run as single processes. For production, this usually means a fairly straight-forward combination of external process management and proxying. Here are some gathered best practices/resources.

调试模式时启用后,将不会缓存模板,并且该应用将在开发过程中自动重启.但是,如果发生Python语法错误,此操作将失败. (可以使用一些其他代码或通过在开发中使用主管)

When debug mode is enabled, templates are not cached and the app will automatically restart during development. This will fail if a Python syntax error occurs, however. (This can be worked around w/ some additional code or by using Supervisor in development)

您可能希望通过终端多路复用器(如屏幕" tmux 可以让您更灵活地运行并跟踪致命错误.

You might want to run your app from a terminal multiplexer like screen or tmux for more flexibility in leaving things running and tracing fatal errors.

通常在生产中,使用前端代理运行多个龙卷风应用程序进程(每个内核至少一个).龙卷风开发者bdarnell有一个 tornado-production-skeleton 使用主管(流程管理)和 nginx (代理).

Typically in production, multiple tornado app processes are run (at least one per core) with a frontend proxy. Tornado developer bdarnell has a tornado-production-skeleton illustrating this using Supervisor (process management) and nginx (proxying).

传统上,Tornado应用程序是单进程的,需要外部进程管理器,但是 HTTPServer可以与多个进程一起运行.此外,还有几个其他帮助程序可以帮助您管理多个流程.

Traditionally, Tornado apps are single-process and require an external process manager, however HTTPServer can be run with multiple processes. Additionally, there are a couple additional helpers for helping out with managing multiple processes.

  • Managing multiple Pylons apps with Supervisor - an excellent tutorial for getting started with Supervisor
  • Deploy tornado application - short tutorial w/ Supervisor and nginx setup walkthrough
  • supervisord-example.conf - this is an example cfg for running 4 tornado instances
  • Nginx Supervisod Module - this module allows nginx to start/stop backends on demand
  • start-stop-daemon example - if you are running a standard Linux system this is an easy way to daemonize your Tornado app
  • Upstart example - Upstart is built into Ubuntu and can respawn crashed instances.

如上所述,Tornado的可以配置HTTPServer 用于单个或多个套接字上的两个进程.

As mentioned above, Tornado's HTTPServer can be configured for both multiple processes on a single or multiple sockets.

官方文档包括将nginx作为负载平衡代理运行并为静态文件提供服务的示例.

The official docs includes an example for running nginx as a load balancing proxy and for serving static files.

  • Deploying Python web (Tornado) applications to multiple servers - short discussion on using a Load Balancer for live migration w/o downtime
  • Rolling Deployment w/ Fabric
  • Python Deployment Anti-Patterns
  • buedafab - a nice collection of Fabricdeployment scripts w/ EC2

这篇关于Tornado Python作为守护程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:21
查看更多