@contextmanager
def cache_server(return_failed=False, cache_root=None):
 queue = Queue()
 process = Process(target=_cache_server_process, args=(queue, return_failed, cache_root))
 process.start()
 try:
  port = queue.get()
  (yield TestCacheServer(u'http://localhost:{0}'.format(port), cache_root))
 finally:
  process.terminate()

@ contextmanager def cache_server ( return_failed = False , cache_root = None ) : queue = Queue ( ) process = Process ( target = _cache_server_process , args = ( queue , return_failed , cache_root ) ) process . start ( ) try : port = queue . get ( ) ( yield TestCacheServer ( u'http://localhost:{0}' . format ( port ) , cache_root ) ) finally : process . terminate ( )
a context manager which launches a temporary cache server on a random port .