homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tarek
Recipients tarek
Date 2012年02月21日.14:12:07
SpamBayes Score 0.00015159608
Marked as misclassified No
Message-id <1329833528.5.0.177059033602.issue14073@psf.upfronthosting.co.za>
In-reply-to
Content
If you try to run the code below and stop it with ctrl+C, it will lock because atexit is never reached.
Antoine proposed to add a way to have one atexit() per thread, so we can call some cleanup code when the app shuts down and there are running threads.
{{{
from wsgiref.simple_server import make_server
import threading
import time
import atexit
class Work(threading.Thread):
 def __init__(self):
 threading.Thread.__init__(self)
 self.running = False
 def run(self):
 self.running = True
 while self.running:
 time.sleep(.2)
 def stop(self):
 self.running = False
 self.join()
worker = Work()
def shutdown():
 # bye-bye
 print 'bye bye'
 worker.stop()
atexit.register(shutdown)
def hello_world_app(environ, start_response):
 status = '200 OK' # HTTP Status
 headers = [('Content-type', 'text/plain')]
 start_response(status, headers)
 return ["Hello World"]
def main():
 worker.start()
 return make_server('', 8000, hello_world_app)
if __name__ == '__main__':
 server = main()
 server.serve_forever()
}}}
History
Date User Action Args
2012年02月21日 14:12:08tareksetrecipients: + tarek
2012年02月21日 14:12:08tareksetmessageid: <1329833528.5.0.177059033602.issue14073@psf.upfronthosting.co.za>
2012年02月21日 14:12:07tareklinkissue14073 messages
2012年02月21日 14:12:07tarekcreate

AltStyle によって変換されたページ (->オリジナル) /