Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to programmatically exit from wsgi's serve_forever() loop

Reply
Thread Tools

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

 
 
Ian Kelly
Guest
Posts: n/a
 
      12-28-2010
On 12/27/2010 6:05 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) 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_foreve r)

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
I don't get why sys.exit(1) doesn't exit the while loop in the follow case chad Python 14 10-13-2010 09:08 AM
Try to exit inner loop and start next iteration of outter loop. Nene Perl Misc 6 12-13-2008 12:20 AM
Code to Exit Web App and Exit Internet Explorer =?Utf-8?B?U2FuZHk=?= ASP .Net 7 08-05-2005 01:55 AM



Advertisments