I'm writing a pair of simple WSGI applications to get a feel for the standard, and I'm to the point where I'd like to test that my applications are working as expected. Now I'm trying to figure out the best way start and stop a server hosting those applications.
My first thought was to start up the SimpleServer from wsgiref in the setUp method and shut it down in the tearDown method. Since serve_forever blocks, I did that work in a separate Thread. Unfortunately, if I use serve_forever to start the server, the secondary thread it's in never dies, and it turns out threading doesn't expose a way to kill a Thread.
Now I'm considering using something like this as my run implementation in the server's Thread:
while keep_going:
httpd.handle_request()
where keep_going is a variable that I set to True in my setUp and set to False in my tearDown.
Is there a better way? I was hoping to write these apps and tests using just the standard library—the better to understand what I'm abstracting away when I use a lib/framework—but this seems like an awful lot of trouble.
Thanks.