如何关闭cherrypy服务器?

时间:2012-08-28 09:01:39

标签: python cherrypy

我在win7上,我开始了一个教程helloworld.py,一切都很好,但我不知道如何退出service.i使用

quit()

但是命令行给我一条错误消息并退出。但是服务仍然在运行并占用我的8080端口。我没有办法手动关闭它。

  File "C:\python32\lib\site-packages\cherrypy\process\wspbus.py", line 197, in
publish
    output.append(listener(*args, **kwargs))
  File "C:\python32\lib\site-packages\cherrypy\_cpserver.py", line 151, in start

    ServerAdapter.start(self)
  File "C:\python32\lib\site-packages\cherrypy\process\servers.py", line 167, in
 start
    wait_for_free_port(*self.bind_addr)
  File "C:\python32\lib\site-packages\cherrypy\process\servers.py", line 410, in
 wait_for_free_port
    raise IOError("Port %r not free on %r" % (port, host))
IOError: Port 8080 not free on '0.0.0.0'

2 个答案:

答案 0 :(得分:4)

根据this pagequit()不适合此任务。

根据您运行服务器的方式,您应该考虑使用cherrypy.engine.exit

>>> help(cherrypy.engine.exit)
exit(self) method of cherrypy.process.win32.Win32Bus instance
    Stop all services and prepare to exit the process.

答案 1 :(得分:4)

将此内容包含在您的python文件中。

@cherrypy.expose

def shutdown(self):  
    cherrypy.engine.exit()

然后在您的页面上添加一个链接。

<a id="shutdown"; href="./shutdown">Shutdown Server</a>
相关问题