I'm writing a web application in python, and using lettuce with splinter to write acceptance tests for it.
In order to do this, I need to get a wsgi server to start my application in the background, so that the application is available for my test suite. To do this, I've been spinning up a waitress server instance in another thread, for the browser being driven to connect to:
def setUp():
base = os.path.dirname(__file__) + "/../../.."
world.app = loadapp('config:test.ini', relative_to=base)
world.server_thread = thread.start_new_thread(serve_app, (world.app,))
def serve_app(app):
serve(app, host='0.0.0.0', port=7654)
This works quite nicely - The running application instance is available to my test suite in order to set up fixtures / mocks etc, and the server is available for my tests to connect to. However, when the tests finish, I've no way of sending a signal to the server to shut itself down cleanly. Therefore, is there anyway I can somehow either send a KeyboardInterrupt
to the server thread I spawn (which will be caught by waitress and will prompt it to shut down cleanly), or failing that, is there an existing wsgi server implementation which exposes non-blocking start()
and stop()
methods that I could employ instead of waitress?