Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to shut down cherrypy server?

im on win7 ,i started a tutorial helloworld.py and everything doing fine but i don't know how to quit the service.i use

quit()

but command line give me an error message and exit.but service is still running and take my 8080 port. i hadn't find a way to shut down it manually.

  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'
like image 392
Max Avatar asked Aug 28 '12 09:08

Max


2 Answers

According to this page, quit() is not appropriate for this task.

Depending on how you run your server, you should consider using 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.
like image 196
icecrime Avatar answered Oct 18 '22 05:10

icecrime


Include this in your python file.

@cherrypy.expose

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

Then add a link on your page.

<a id="shutdown"; href="./shutdown">Shutdown Server</a>
like image 23
yvonnezoe Avatar answered Oct 18 '22 04:10

yvonnezoe