@contextmanager
def webserver(app, port=0, host=None):
 server = build_web_server(app, port, (host or '127.0.0.1'))
 (host, port) = server.socket.getsockname()
 import threading
 thread = threading.Thread(target=server.serve_forever, kwargs={'poll_interval': 0.5})
 thread.setDaemon(True)
 thread.start()
 try:
  (yield ('http://%s:%s/' % (host, port)))
 finally:
  server.shutdown()
  server.server_close()

@ contextmanager def webserver ( app , port = 0 , host = None ) : server = build_web_server ( app , port , ( host or '127.0.0.1' ) ) ( host , port ) = server . socket . getsockname ( ) import threading thread = threading . Thread ( target = server . serve_forever , kwargs = { 'poll_interval' : 0.5 } ) thread . setDaemon ( True ) thread . start ( ) try : ( yield ( 'http://%s:%s/' % ( host , port ) ) ) finally : server . shutdown ( ) server . server_close ( )
context manager entry point for the with statement .