如何关闭CherryPy服务器?

9

我正在使用win7系统,开始学习helloworld.py的教程并且一切进行得很顺利,但是我不知道如何退出该服务。我使用

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个回答

8

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

@cherrypy.expose

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

在你的页面上添加一个链接。
<a id="shutdown"; href="./shutdown">Shutdown Server</a>

7
根据这个页面的说法,quit()不适合此任务。
根据您运行服务器的方式,可以考虑使用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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接