Esempio n. 1
0
def _prepare_lazyflow_config( parsed_args ):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)

    # Convert str -> int
    if n_threads is not None:
        n_threads = int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    if n_threads is None:
        n_threads = ilastik_config.getint('lazyflow', 'threads')
        if n_threads == -1:
            n_threads = None
    total_ram_mb = total_ram_mb or ilastik_config.getint('lazyflow', 'total_ram_mb')
    
    # Note that n_threads == 0 is valid and useful for debugging.
    if (n_threads is not None) or total_ram_mb:
        def _configure_lazyflow_settings(shell):
            import lazyflow
            import lazyflow.request
            if n_threads is not None:
                logger.info("Resetting lazyflow thread pool with {} threads.".format( n_threads ))
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception("In your current configuration, RAM is limited to {} MB."
                                    "  Remember to specify RAM in MB, not GB."
                                    .format( total_ram_mb ))
                logger.info("Configuring lazyflow RAM limit to {} MB".format( total_ram_mb ))
                lazyflow.AVAILABLE_RAM_MB = total_ram_mb
        return _configure_lazyflow_settings
    return None
Esempio n. 2
0
def _prepare_lazyflow_config( parsed_args ):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)

    # Convert str -> int
    n_threads = n_threads and int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    n_threads = n_threads or ilastik_config.getint('lazyflow', 'threads')
    total_ram_mb = total_ram_mb or ilastik_config.getint('lazyflow', 'total_ram_mb')
    
    if n_threads or total_ram_mb:
        def _configure_lazyflow_settings(shell):
            import lazyflow
            import lazyflow.request
            if n_threads > 0:
                logger.info("Resetting lazyflow thread pool with {} threads.".format( n_threads ))
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception("In your current configuration, RAM is limited to {} MB."
                                    "  Remember to specify RAM in MB, not GB."
                                    .format( total_ram_mb ))
                logger.info("Configuring lazyflow RAM limit to {} MB".format( total_ram_mb ))
                lazyflow.AVAILABLE_RAM_MB = total_ram_mb
        return _configure_lazyflow_settings
    return None
Esempio n. 3
0
def _prepare_lazyflow_config(parsed_args):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)
    status_interval_secs = int(
        os.getenv("LAZYFLOW_STATUS_MONITOR_SECONDS", "0"))

    # Convert str -> int
    if n_threads is not None:
        n_threads = int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    if n_threads is None:
        n_threads = ilastik_config.getint('lazyflow', 'threads')
        if n_threads == -1:
            n_threads = None
    total_ram_mb = total_ram_mb or ilastik_config.getint(
        'lazyflow', 'total_ram_mb')

    # Note that n_threads == 0 is valid and useful for debugging.
    if (n_threads is not None) or total_ram_mb or status_interval_secs:

        def _configure_lazyflow_settings():
            import lazyflow
            import lazyflow.request
            from lazyflow.utility import Memory
            from lazyflow.operators.cacheMemoryManager import CacheMemoryManager

            if status_interval_secs:
                memory_logger = logging.getLogger(
                    'lazyflow.operators.cacheMemoryManager')
                memory_logger.setLevel(logging.DEBUG)
                CacheMemoryManager().setRefreshInterval(status_interval_secs)

            if n_threads is not None:
                logger.info(
                    "Resetting lazyflow thread pool with {} threads.".format(
                        n_threads))
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception(
                        "In your current configuration, RAM is limited to {} MB."
                        "  Remember to specify RAM in MB, not GB.".format(
                            total_ram_mb))
                ram = total_ram_mb * 1024**2
                fmt = Memory.format(ram)
                logger.info("Configuring lazyflow RAM limit to {}".format(fmt))
                Memory.setAvailableRam(ram)

        return _configure_lazyflow_settings
    return None
Esempio n. 4
0
def _prepare_lazyflow_config(parsed_args):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)
    status_interval_secs = int(
        os.getenv("LAZYFLOW_STATUS_MONITOR_SECONDS", "0"))

    # Convert str -> int
    if n_threads is not None:
        n_threads = int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    if n_threads is None:
        n_threads = ilastik_config.getint('lazyflow', 'threads')
        if n_threads == -1:
            n_threads = None
    total_ram_mb = total_ram_mb or ilastik_config.getint(
        'lazyflow', 'total_ram_mb')

    # Note that n_threads == 0 is valid and useful for debugging.
    if (n_threads is not None) or total_ram_mb or status_interval_secs:
        def _configure_lazyflow_settings():
            import lazyflow
            import lazyflow.request
            from lazyflow.utility import Memory
            from lazyflow.operators.cacheMemoryManager import \
                CacheMemoryManager

            if status_interval_secs:
                memory_logger = logging.getLogger(
                    'lazyflow.operators.cacheMemoryManager')
                memory_logger.setLevel(logging.DEBUG)
                CacheMemoryManager().setRefreshInterval(status_interval_secs)

            if n_threads is not None:
                logger.info(f'Resetting lazyflow thread pool with {n_threads} '
                            'threads.')
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception('In your current configuration, RAM is '
                                    f'limited to {total_ram_mb} MB. Remember '
                                    'to specify RAM in MB, not GB.')
                ram = total_ram_mb * 1024**2
                fmt = Memory.format(ram)
                logger.info("Configuring lazyflow RAM limit to {}".format(fmt))
                Memory.setAvailableRam(ram)
        return _configure_lazyflow_settings
    return None
Esempio n. 5
0
def _prepare_lazyflow_config(parsed_args):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)

    # Convert str -> int
    if n_threads is not None:
        n_threads = int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    if n_threads is None:
        n_threads = ilastik_config.getint('lazyflow', 'threads')
        if n_threads == -1:
            n_threads = None
    total_ram_mb = total_ram_mb or ilastik_config.getint(
        'lazyflow', 'total_ram_mb')

    # Note that n_threads == 0 is valid and useful for debugging.
    if (n_threads is not None) or total_ram_mb:

        def _configure_lazyflow_settings():
            import lazyflow
            import lazyflow.request
            if n_threads is not None:
                logger.info(
                    "Resetting lazyflow thread pool with {} threads.".format(
                        n_threads))
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception(
                        "In your current configuration, RAM is limited to {} MB."
                        "  Remember to specify RAM in MB, not GB.".format(
                            total_ram_mb))
                ram = total_ram_mb * 1024**2
                fmt = Memory.format(ram)
                logger.info("Configuring lazyflow RAM limit to {}".format(fmt))
                Memory.setAvailableRam(ram)

        return _configure_lazyflow_settings
    return None
Esempio n. 6
0
def _prepare_lazyflow_config(parsed_args):
    n_threads = ilastik_config.getint("lazyflow", "threads")
    total_ram_mb = ilastik_config.getint("lazyflow", "total_ram_mb")
    if n_threads or total_ram_mb:

        def _configure_lazyflow_settings(shell):
            import lazyflow
            import lazyflow.request

            if n_threads > 0:
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb < 500:
                raise Exception(
                    "Your config says available RAM is only {} MB.  "
                    "Remember to specify RAM in MB, not GB.".format(total_ram_mb)
                )
            lazyflow.AVAILABLE_RAM_MB = total_ram_mb

        return _configure_lazyflow_settings
    return None
Esempio n. 7
0
def _prepare_lazyflow_config(parsed_args):
    # Check environment variable settings.
    n_threads = os.getenv("LAZYFLOW_THREADS", None)
    total_ram_mb = os.getenv("LAZYFLOW_TOTAL_RAM_MB", None)

    # Convert str -> int
    if n_threads is not None:
        n_threads = int(n_threads)
    total_ram_mb = total_ram_mb and int(total_ram_mb)

    # If not in env, check config file.
    if n_threads is None:
        n_threads = ilastik_config.getint("lazyflow", "threads")
        if n_threads == -1:
            n_threads = None
    total_ram_mb = total_ram_mb or ilastik_config.getint("lazyflow", "total_ram_mb")

    # Note that n_threads == 0 is valid and useful for debugging.
    if (n_threads is not None) or total_ram_mb:

        def _configure_lazyflow_settings():
            import lazyflow
            import lazyflow.request
            from lazyflow.utility import Memory

            if n_threads is not None:
                logger.info("Resetting lazyflow thread pool with {} threads.".format(n_threads))
                lazyflow.request.Request.reset_thread_pool(n_threads)
            if total_ram_mb > 0:
                if total_ram_mb < 500:
                    raise Exception(
                        "In your current configuration, RAM is limited to {} MB."
                        "  Remember to specify RAM in MB, not GB.".format(total_ram_mb)
                    )
                ram = total_ram_mb * 1024 ** 2
                fmt = Memory.format(ram)
                logger.info("Configuring lazyflow RAM limit to {}".format(fmt))
                Memory.setAvailableRam(ram)

        return _configure_lazyflow_settings
    return None