human
Complete this python program:
def conditional_flush(max_rmem, force=False):
assistant
#Here is the Python program you requested.

    """Flush the cache if the estimated memory usage exceeds `max_rmem`.
    The flusher has a timeout to avoid flushing over and over
    in particular situations (this means that for some setups
    the memory usage will exceed the requirement and a server with
    more memory is probably required for the given game).
    Args:
    max_rmem (int): memory-usage estimation-treshold after which
    cache is flushed.
    force (bool, optional): forces a flush, regardless of timeout.
    Defaults to `False`.
    """
    global LAST_FLUSH
    def mem2cachesize(desired_rmem):
        '\n                                Estimate    the    size    of    the    idmapper    cache    based    on    the    memory\n                                desired.    This    is    used    to    optionally    cap    the    cache    size.\n\n                                desired_rmem    -    memory    in    MB    (minimum    50MB)\n\n                                The    formula    is    empirically    estimated    from    usage    tests    (Linux)\n                                and    is\n                                                Ncache    =    RMEM    -    35.0    /    0.0157\n                                where    RMEM    is    given    in    MB    and    Ncache    is    the    size    of    the    cache\n                                for    this    memory    usage.    VMEM    tends    to    be    about    100MB    higher\n                                than    RMEM    for    large    memory    usage.\n                                '
        vmem = max(desired_rmem, 50.0)
        Ncache = int((abs((float(vmem) - 35.0)) / 0.0157))
        return Ncache
    if (not max_rmem):
        return
    now = time.time()
    if (not LAST_FLUSH):
        LAST_FLUSH = now
        return
    if (((now - LAST_FLUSH) < AUTO_FLUSH_MIN_INTERVAL) and (not force)):
        logger.log_warn(('Warning:    Idmapper    flush    called    more    than    once    in    %s    min    interval.    Check    memory    usage.' % (AUTO_FLUSH_MIN_INTERVAL / 60.0)))
        return
    if (os.name == 'nt'):
        return
    Ncache_max = mem2cachesize(max_rmem)
    (Ncache, _) = cache_size()
    actual_rmem = (float(os.popen(('ps    -p    %d    -o    %s    |    tail    -1' % (os.getpid(), 'rss'))).read()) / 1000.0)
    if ((Ncache >= Ncache_max) and (actual_rmem > (max_rmem * 0.9))):
        flush_cache()
        LAST_FLUSH = now