Re: How to programmatically exit from wsgi's serve_forever() loop

Discussion in 'Python' started by Ian Kelly, Dec 28, 2010.

  1. Ian Kelly

    Ian Kelly Guest

    On 12/27/2010 6:05 PM, wrote:
    > Is it possible to programmatically exit from the wsgiref's
    > serve_forever() loop?
    > I tried the following, all without success:
    > httpd.server_close()
    > httpd.shutdown()
    > sys.exit(1)
    > os._exit(1) (shouldn't this always abort an application?)
    > raise KeyboardInterupt (Ctrl+Break from console works)



    >>> help(wsgiref.simple_server.WSGIServer.serve_forever)

    Help on method serve_forever in module SocketServer:

    serve_forever(self, poll_interval=0.5) unbound
    wsgiref.simple_server.WSGIServer method
    Handle one request at a time until shutdown.

    Polls for shutdown every poll_interval seconds. Ignores
    self.timeout. If you need to do periodic tasks, do them in
    another thread.

    >>> help(wsgiref.simple_server.WSGIServer.shutdown)

    Help on method shutdown in module SocketServer:

    shutdown(self) unbound wsgiref.simple_server.WSGIServer method
    Stops the serve_forever loop.

    Blocks until the loop has finished. This must be called while
    serve_forever() is running in another thread, or it will
    deadlock.


    Did you try:

    >>> import threading
    >>> threading.Thread(target=httpd.shutdown).start()


    Cheers,
    Ian
     
    Ian Kelly, Dec 28, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,976
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    66,088
    sandeep1976
    Nov 8, 2006
  3. chad
    Replies:
    14
    Views:
    614
    Arnaud Delobelle
    Oct 13, 2010
  4. Nene
    Replies:
    6
    Views:
    366
    John W. Krahn
    Dec 13, 2008
  5. Isaac Won
    Replies:
    9
    Views:
    451
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page