1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#!/usr/bin/env python
"""A server to test with blocking I/O."""
# Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com>
# All rights reserved. See COPYING file for details.
from __future__ import print_function
import time
from wsgiref.simple_server import make_server
def wait_app(environ, start_response):
"""An application serving blocking pages."""
status = '200 OK'
headers = [('Content-type', 'text/plain')]
start_response(status, headers)
try:
secs = int(environ['PATH_INFO'].replace('/', ''))
except Exception:
secs = 0
time.sleep(secs)
return [str(secs).encode('ascii')]
httpd = make_server('', 8000, wait_app)
print("Serving on port 8000...")
httpd.serve_forever()
|