通过http停止cherrypy服务器 [英] stopping a cherrypy server over http

查看:52
本文介绍了通过http停止cherrypy服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Cherrypy应用程序,正在使用wxpython ui来控制HTTP.我想在ui关闭时杀死服务器,但是我不知道该怎么做.现在,我只是在窗口关闭事件上执行sys.exit(),但这导致

I have a cherrypy app that I'm controlling over http with a wxpython ui. I want to kill the server when the ui closes, but I don't know how to do that. Right now I'm just doing a sys.exit() on the window close event but thats resulting in

Traceback (most recent call last):
  File "ui.py", line 67, in exitevent
    urllib.urlopen("http://"+server+"/?sigkill=1")
  File "c:\python26\lib\urllib.py", line 87, in urlopen
    return opener.open(url)
  File "c:\python26\lib\urllib.py", line 206, in open
    return getattr(self, name)(url)
  File "c:\python26\lib\urllib.py", line 354, in open_http
    'got a bad status line', None)
IOError: ('http protocol error', 0, 'got a bad status line', None)

那是因为我没有适当地停止cherrypy吗?

is that because I'm not stopping cherrypy properly?

推荐答案

您如何停止CherryPy?通过发送SIGKILL给自己?您至少应该发送TERM,但更好的方法是调用 cherrypy.engine.exit()(版本3.1+).两种技术都可以让CherryPy更正常地关闭,其中包括允许任何进程中的请求(例如您的?sigkill = 1"请求本身)完成并完全关闭.

How are you stopping CherryPy? By sending a SIGKILL to itself? You should send TERM instead at the least, but even better would be to call cherrypy.engine.exit() (version 3.1+). Both techniques will allow CherryPy to shut down more gracefully, which includes allowing any in-process requests (like your "?sigkill=1" request itself) to finish up and close cleanly.

这篇关于通过http停止cherrypy服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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