2012-08-28 156 views
5

IM Win7上,我開始了一個教程helloworld.py,一切都做得很好,但我不知道如何退出service.i使用如何關閉cherrypy服務器?

quit() 

但命令行給我一個錯誤消息,並且exit.but服務仍在運行,並採取我的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

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. 
4

在你的Python文件中包含這一點。

@cherrypy.expose 

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

然後在您的頁面上添加一個鏈接。

<a id="shutdown"; href="./shutdown">Shutdown Server</a>