2014-09-06 70 views
2

创建下面的函数来关机cherrypy我如何关闭CherryPy的

import cherrypy 
cherrypy.engine.exit() 

的文件的名称:shutdown.py。然后我在命令行中输入命令python shutdown.py。以下消息显示:

[06/Sep/2014:11:28:22] ENGINE Bus STOPPING 
[06/Sep/2014:11:28:22] ENGINE HTTP Server None already shut down 
[06/Sep/2014:11:28:22] ENGINE No thread running for None. 
[06/Sep/2014:11:28:22] ENGINE No thread running for None. 
[06/Sep/2014:11:28:22] ENGINE Bus STOPPED 
[06/Sep/2014:11:28:22] ENGINE Bus EXITING 
[06/Sep/2014:11:28:22] ENGINE Bus EXITED 

但是,CherryPy仍在运行。那么我如何关闭CherryPy?

另外,如果我有多个cherrypy服务器在同一时间运行? shutdown.py是否会杀死所有人?

+0

你正在运行哪个操作系统?你需要使用信号来杀死另一个进程。没有全球cherrypy服务器。 – cyraxjoe 2014-09-06 05:36:43

+0

操作系统:Ubuntu 14.04 LTS。 – 2014-09-06 09:26:54

回答

2

CherryPy应用程序包含在普通的Python进程中。要将CherryPy应用程序视为服务器(例如,您可以/etc/init.d/mysql stop的mysql,nginx等),您应该相应地部署它。

对于一个特设的情况下,只是告诉cherryd保存PID文件,--pidfile或直接集成PIDFile plugin到你的代码。然后只是kill `cat /path/to/pidfile`

对于全面部署,请阅读this answer

+0

我已经告诉你 - 使用PIDFile插件。像plugins.PIDFile(引擎,'/run/yourapp/yourapp.pid')。subscribe()''。请查看[樱花来源](https://bitbucket.org/cherrypy/cherrypy/src/2a045705a5e403699aab915ab32ea8484f259fa1/cherrypy/cherryd?at=default#cl-39)。 – saaj 2014-09-08 15:06:40

+0

明白了,非常感谢。 – 2014-09-09 00:35:50