wsgi server shutdown on Win32

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

wsgi server shutdown on Win32

Florent Aide
Hi all,

I am currently testing some concepts (see attached file). This comes
from a paste Ben Bangert did in pylon's project paster :)
I just adapted it to use CP 3.1beta from svn trunk (currently using r1835).

This works wonderfully well under Linux, I asked Mark Ramm and he
confirms that all works well under MacOSX. But when I use this under
windows I cannot shutdown the server.

When I press CTRL-C in the console where I started the app I get those
messages printed on the console:

[19/Dec/2007:18:45:03] ENGINE Console event 0: shutting down bus
[19/Dec/2007:18:45:03] ENGINE Bus stopping

But it never stops. I can press CTRL-C as many times as I want, it
will always print those two lines and do no more.
Is there a known issue regarding the shutdown of the wsgi server on
the win32 platform ?

Thanks in advance for your help,
Florent Aide.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---


from optparse import OptionParser

from cherrypy import wsgiserver
from routes import Mapper
from routes.middleware import RoutesMiddleware
from webob import Response, Request
from weberror.evalexception import EvalException
import sys

# Parser the command line options
parser = OptionParser()
parser.add_option('-d', action="store_true", dest="debug")
(options, args) = parser.parse_args()

# Create our app
class MyApp(object):
    def __init__(self, controllers, mapper):
        self.controllers = controllers
        mapper.create_regs(controllers.keys())
   
    def __call__(self, environ, start_response):
        print "environ: %s, start_response: %s" % (environ, start_response)
        match = environ['wsgiorg.routing_args'][1]
        print "match = %s" % match
        resp = Response()
        if match is None:
            print "No Matching... returning 404"
            resp.status_int = 404
            return resp(environ, start_response)

        controller = self.controllers[match['controller']]()
        action = getattr(controller, match['action'], None)
        if not action:
            resp.status_int = 404
            return resp(environ, start_response)
       
        req = Request(environ)
        response = action(req, resp)
        return response(environ, start_response)

# Create a simple controller
class Home(object):
    def index(self, request, response):
        response.body = "Hello world!"
        return response

class Index(object):
    def index(self, request, response):
        response.body = "Index page reached!"
        return response

# Make the mapper
mapper = Mapper()
mapper.connect(':controller/:action')

controllers = {
        'home': Home,
        '': Index,
        }
# Create our app with the mapper
app = MyApp(controllers=controllers, mapper=mapper)
app = RoutesMiddleware(app, mapper)

# If we're in debug, add the evalexception
if options.debug:
    app = EvalException(app)

wsgi_apps = [('/', app)]
server = wsgiserver.CherryPyWSGIServer(('127.0.0.1', 5004), wsgi_apps,
    server_name='localhost', request_queue_size=100)

if __name__ == '__main__':
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()

Reply | Threaded
Open this post in threaded view
|

Re: wsgi server shutdown on Win32

Robert Brewer-4

Florent Aide wrote:

> I am currently testing some concepts (see attached file). This comes
> from a paste Ben Bangert did in pylon's project paster :)
> I just adapted it to use CP 3.1beta from svn trunk (currently using
> r1835).
>
> This works wonderfully well under Linux, I asked Mark Ramm and he
> confirms that all works well under MacOSX. But when I use this under
> windows I cannot shutdown the server.
>
> When I press CTRL-C in the console where I started the app I get those
> messages printed on the console:
>
> [19/Dec/2007:18:45:03] ENGINE Console event 0: shutting down bus
> [19/Dec/2007:18:45:03] ENGINE Bus stopping
>
> But it never stops. I can press CTRL-C as many times as I want, it
> will always print those two lines and do no more.
> Is there a known issue regarding the shutdown of the wsgi server on
> the win32 platform ?

There is now, I guess. :) This seems to be related to
http://groups.google.com/group/cherrypy-devel/browse_frm/thread/b58a15a9
7b539afa

Until it's officially fixed, you should be able to work around it by
commenting out the SetConsoleCtrlHandler call inside
cherrypy/restsrv/win32.py.


Robert Brewer
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: wsgi server shutdown on Win32

Florent Aide

On Dec 24, 2007 6:43 AM, Robert Brewer <[hidden email]> wrote:

> Florent Aide wrote:

[...]

> > But it never stops. I can press CTRL-C as many times as I want, it
> > will always print those two lines and do no more.
> > Is there a known issue regarding the shutdown of the wsgi server on
> > the win32 platform ?
>
> There is now, I guess. :) This seems to be related to
> http://groups.google.com/group/cherrypy-devel/browse_frm/thread/b58a15a9
> 7b539afa
>
> Until it's officially fixed, you should be able to work around it by
> commenting out the SetConsoleCtrlHandler call inside
> cherrypy/restsrv/win32.py.

I confirm that it now works as expected on win32.

Thanks Robert.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: wsgi server shutdown on Win32

Robert Brewer-4
In reply to this post by Robert Brewer-4

> Florent Aide wrote:
> > I am currently testing some concepts (see attached file). This comes
> > from a paste Ben Bangert did in pylon's project paster :)
> > I just adapted it to use CP 3.1beta from svn trunk (currently using
> > r1835).
> >
> > This works wonderfully well under Linux, I asked Mark Ramm and he
> > confirms that all works well under MacOSX. But when I use this under
> > windows I cannot shutdown the server.
> >
> > When I press CTRL-C in the console where I started the app I get
> those
> > messages printed on the console:
> >
> > [19/Dec/2007:18:45:03] ENGINE Console event 0: shutting down bus
> > [19/Dec/2007:18:45:03] ENGINE Bus stopping
> >
> > But it never stops. I can press CTRL-C as many times as I want, it
> > will always print those two lines and do no more.
> > Is there a known issue regarding the shutdown of the wsgi server on
> > the win32 platform ?
>
> There is now, I guess. :) This seems to be related to
> http://groups.google.com/group/cherrypy-
> devel/browse_frm/thread/b58a15a9
> 7b539afa
>
> Until it's officially fixed, you should be able to work around it by
> commenting out the SetConsoleCtrlHandler call inside
> cherrypy/restsrv/win32.py.

Okay, fixed in http://www.cherrypy.org/changeset/1842. If you never call
engine.start(), the console handler won't ever be set. If you still
don't want one but do need to call engine.start, it's as easy as
executing:

    cherrypy._console_control_handler.unsubscribe()

...before you call engine.start.


Robert Brewer
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---