8

我在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'
4

2 回答 2

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.
于 2012-08-28T09:07:59.450 回答
7

将其包含在您的 python 文件中。

@cherrypy.expose

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

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

<a id="shutdown"; href="./shutdown">Shutdown Server</a>
于 2013-04-23T00:49:54.417 回答