當前位置: 首頁>>代碼示例>>Python>>正文


Python distributed.LocalCluster方法代碼示例

本文整理匯總了Python中distributed.LocalCluster方法的典型用法代碼示例。如果您正苦於以下問題:Python distributed.LocalCluster方法的具體用法?Python distributed.LocalCluster怎麽用?Python distributed.LocalCluster使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在distributed的用法示例。


在下文中一共展示了distributed.LocalCluster方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: spawn_cluster_and_client

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def spawn_cluster_and_client(
    address: Optional[str] = None, **kwargs
) -> Tuple[Optional[LocalCluster], Optional[Client]]:
    """
    If provided an address, create a Dask Client connection.
    If not provided an address, create a LocalCluster and Client connection.
    If not provided an address, other Dask kwargs are accepted and passed down to the
    LocalCluster object.

    Notes
    -----
    When using this function, the processing machine or container must have networking
    capabilities enabled to function properly.
    """
    cluster = None
    if address is not None:
        client = Client(address)
        log.info(f"Connected to Remote Dask Cluster: {client}")
    else:
        cluster = LocalCluster(**kwargs)
        client = Client(cluster)
        log.info(f"Connected to Local Dask Cluster: {client}")

    return cluster, client 
開發者ID:AllenCellModeling,項目名稱:aicsimageio,代碼行數:26,代碼來源:dask_utils.py

示例2: shutdown_cluster_and_client

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def shutdown_cluster_and_client(
    cluster: Optional[LocalCluster], client: Optional[Client]
) -> Tuple[Optional[LocalCluster], Optional[Client]]:
    """
    Shutdown a cluster and client.

    Notes
    -----
    When using this function, the processing machine or container must have networking
    capabilities enabled to function properly.
    """
    if cluster is not None:
        cluster.close()
    if client is not None:
        client.shutdown()
        client.close()

    return cluster, client 
開發者ID:AllenCellModeling,項目名稱:aicsimageio,代碼行數:20,代碼來源:dask_utils.py

示例3: start_cluster

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def start_cluster(diagnostics_port=0):
    "Set up a LocalCluster for distributed"
    
    hostname = socket.gethostname()
    n_workers = os.cpu_count() // 2
    cluster = LocalCluster(ip='localhost',
                       n_workers=n_workers,
                       diagnostics_port=diagnostics_port,
                       memory_limit=6e9)
    client = Client(cluster)

    params = { 'bokeh_port': cluster.scheduler.services['bokeh'].port,
           'user': getpass.getuser(),
           'scheduler_ip': cluster.scheduler.ip,
           'hostname': hostname, }

    print("If the link to the dashboard below doesn't work, run this command on a local terminal to set up a SSH tunnel:")
    print()
    print("  ssh -N -L {bokeh_port}:{scheduler_ip}:{bokeh_port} {hostname}.nci.org.au -l {user}".format(**params) )
    
    return client 
開發者ID:COSIMA,項目名稱:cosima-cookbook,代碼行數:23,代碼來源:distributed.py

示例4: _n_workers_for_local_cluster

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def _n_workers_for_local_cluster(calcs):
    """The number of workers used in a LocalCluster

    An upper bound is set at the cpu_count or the number of calcs submitted,
    depending on which is smaller.  This is to prevent more workers from
    being started than needed (but also to prevent too many workers from
    being started in the case that a large number of calcs are submitted).
    """
    return min(cpu_count(), len(calcs)) 
開發者ID:spencerahill,項目名稱:aospy,代碼行數:11,代碼來源:automate.py

示例5: _exec_calcs

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def _exec_calcs(calcs, parallelize=False, client=None, **compute_kwargs):
    """Execute the given calculations.

    Parameters
    ----------
    calcs : Sequence of ``aospy.Calc`` objects
    parallelize : bool, default False
        Whether to submit the calculations in parallel or not
    client : distributed.Client or None
        The distributed Client used if parallelize is set to True; if None
        a distributed LocalCluster is used.
    compute_kwargs : dict of keyword arguments passed to ``Calc.compute``

    Returns
    -------
    A list of the values returned by each Calc object that was executed.
    """
    if parallelize:
        def func(calc):
            """Wrap _compute_or_skip_on_error to require only the calc
            argument"""
            if 'write_to_tar' in compute_kwargs:
                compute_kwargs['write_to_tar'] = False
            return _compute_or_skip_on_error(calc, compute_kwargs)

        if client is None:
            n_workers = _n_workers_for_local_cluster(calcs)
            with distributed.LocalCluster(n_workers=n_workers) as cluster:
                with distributed.Client(cluster) as client:
                    result = _submit_calcs_on_client(calcs, client, func)
        else:
            result = _submit_calcs_on_client(calcs, client, func)
        if compute_kwargs['write_to_tar']:
            _serial_write_to_tar(calcs)
        return result
    else:
        return [_compute_or_skip_on_error(calc, compute_kwargs)
                for calc in calcs] 
開發者ID:spencerahill,項目名稱:aospy,代碼行數:40,代碼來源:automate.py

示例6: external_client

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def external_client():
    # Explicitly specify we want only 4 workers so that when running on
    # continuous integration we don't request too many.
    cluster = distributed.LocalCluster(n_workers=4)
    client = distributed.Client(cluster)
    yield client
    client.close()
    cluster.close() 
開發者ID:spencerahill,項目名稱:aospy,代碼行數:10,代碼來源:test_automate.py

示例7: setUp

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def setUp(self):
        self.dagbag = DagBag(include_examples=True)
        self.cluster = LocalCluster() 
開發者ID:apache,項目名稱:airflow,代碼行數:5,代碼來源:test_dask_executor.py

示例8: cluster_and_client

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def cluster_and_client(address: Optional[str] = None, **kwargs):
    """
    If provided an address, create a Dask Client connection.
    If not provided an address, create a LocalCluster and Client connection.
    If not provided an address, other Dask kwargs are accepted and passed down to the
    LocalCluster object.

    These objects will only live for the duration of this context manager.

    Examples
    --------
    >>> with cluster_and_client() as (cluster, client):
    ...     img1 = AICSImage("1.tiff")
    ...     img2 = AICSImage("2.czi")
    ...     other processing

    Notes
    -----
    When using this context manager, the processing machine or container must have
    networking capabilities enabled to function properly.
    """
    try:
        cluster, client = spawn_cluster_and_client(address=address, **kwargs)
        yield cluster, client
    finally:
        shutdown_cluster_and_client(cluster=cluster, client=client) 
開發者ID:AllenCellModeling,項目名稱:aicsimageio,代碼行數:28,代碼來源:dask_utils.py

示例9: setup

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def setup():
    from distributed import LocalCluster, Client
    cluster = LocalCluster(n_workers=1, threads_per_worker=1, processes=False)
    use_distributed(Client(cluster)) 
開發者ID:bccp,項目名稱:nbodykit,代碼行數:6,代碼來源:test_distributed.py

示例10: _get_local_cluster

# 需要導入模塊: import distributed [as 別名]
# 或者: from distributed import LocalCluster [as 別名]
def _get_local_cluster():
        # TODO: Add more parameters and configurations.
        from distributed import LocalCluster
        return LocalCluster() 
開發者ID:yassineAlouini,項目名稱:kaggle-tools,代碼行數:6,代碼來源:dask.py


注:本文中的distributed.LocalCluster方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。