17"""Context manager entry point for the 'with' statement.1819 Pass 0 as port number to dynamically allocate a free port.2021 Usage:2223 with webserver(wsgi_app_function, 8080) as host_url:24 do_ws_calls(host_url)25 """26server=build_web_server(app,port,hostor'127.0.0.1')27host,port=server.socket.getsockname()2829importthreading30thread=threading.Thread(target=server.serve_forever,31kwargs={'poll_interval':0.5})32thread.setDaemon(True)33thread.start()34try:35yield'http://%s:%s/'%(host,port)# yield control to 'with' body36finally:37server.shutdown()38server.server_close()39thread.join(timeout=1)