def memcached_instance(request, watcher_getter, memcached_server_present):
    """Start up an instance of memcached."""

    port = portend.find_available_local_port()

    def is_occupied():
        try:
            portend.Checker().assert_free('localhost', port)
        except Exception:
            return True
        return False

    proc = watcher_getter(
        name='memcached',
        arguments=['-p', str(port)],
        checker=is_occupied,
        request=request,
    )
    return locals()
Start up an instance of memcached.
cherrypy/test/test_session.py