login community faq

I am a newbee in cherrypy programming. I just tried with a sample program of wsgiserver.The program code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from cherrypy import wsgiserver

def my_crazy_app(environ, start_response):
   status = '200 OK'
   response_headers = [('Content-type','text/plain')]
   start_response(status, response_headers)
   return ['Hello world!']

server = wsgiserver.CherryPyWSGIServer(
    ('127.0.0.1', 8080), my_crazy_app,
    server_name='localhost')
server.start()

I got the output Hello world successfully, but the problem is when i hit Ctrl-c on the terminal to stop the server, its not getting stopped. How to do it?

asked Jul 30 '12 at 02:31

Nightfury's gravatar image

Nightfury
12

edited Jul 31 '12 at 01:32


IIRC, the wsgiserver itself is not associated to any signal and therefore doesn't respect the SIGINT interruption. Only the higher level CherryPy engine will provide that. If you can't use it, you probably want to install a handler using the Python signal module.

Well, something along those lines will do the job:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import signal

from cherrypy import wsgiserver 
def my_crazy_app(environ, start_response): 
   status = '200 OK' 
   response_headers = [('Content-type','text/plain')] 
   start_response(status, response_headers) 
   return ['Hello world!']

server = wsgiserver.CherryPyWSGIServer( ('127.0.0.1', 8080), my_crazy_app, server_name='localhost')

def stop_server(*args, **kwargs):
   server.stop()

signal.signal(signal.SIGINT,  stop_server)

server.start()

answered Jul 30 '12 at 03:31

Nightfury's gravatar image

Nightfury
12

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited