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


Python Nanny.start方法代碼示例

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


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

示例1: become_distributed_worker

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
def become_distributed_worker(ip, port, nanny=False, **kwargs):
    """Task function for becoming a distributed Worker

    Parameters
    ----------

    ip: str
        The IP address of the Scheduler.
    port: int
        The port of the Scheduler.
    **kwargs:
        Any additional keyword arguments will be passed to the Worker constructor.
    """
    shell = get_ipython()
    kernel = shell.kernel
    if getattr(kernel, 'distributed_worker', None) is not None:
        kernel.log.info("Distributed worker is already running.")
        return
    from distributed import Worker, Nanny
    if nanny:
        w = Nanny(ip, port, **kwargs)
    else:
        w = Worker(ip, port, **kwargs)
    shell.user_ns['distributed_worker'] = kernel.distributed_worker = w
    w.start(0)
開發者ID:AminJamalzadeh,項目名稱:ipyparallel,代碼行數:27,代碼來源:util.py

示例2: test_broken_worker_during_computation

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
def test_broken_worker_during_computation(c, s, a, b):
    n = Nanny(s.ip, s.port, ncores=2, loop=s.loop)
    n.start(0)

    start = time()
    while len(s.ncores) < 3:
        yield gen.sleep(0.01)
        assert time() < start + 5

    L = c.map(inc, range(256))
    for i in range(8):
        L = c.map(add, *zip(*partition_all(2, L)))

    from random import random
    yield gen.sleep(random() / 2)
    with ignoring(OSError):
        n.process.terminate()
    yield gen.sleep(random() / 2)
    with ignoring(OSError):
        n.process.terminate()

    result = yield c._gather(L)
    assert isinstance(result[0], int)

    yield n._close()
開發者ID:dask,項目名稱:distributed,代碼行數:27,代碼來源:test_worker_failure.py

示例3: test_worker_who_has_clears_after_failed_connection

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
def test_worker_who_has_clears_after_failed_connection(c, s, a, b):
    n = Nanny(s.ip, s.port, ncores=2, loop=s.loop)
    n.start(0)

    start = time()
    while len(s.ncores) < 3:
        yield gen.sleep(0.01)
        assert time() < start + 5

    futures = c.map(slowinc, range(20), delay=0.01,
                    key=['f%d' % i for i in range(20)])
    yield wait(futures)

    result = yield c.submit(sum, futures, workers=a.address)
    for dep in set(a.dep_state) - set(a.task_state):
        a.release_dep(dep, report=True)

    n_worker_address = n.worker_address
    with ignoring(CommClosedError):
        yield c._run(os._exit, 1, workers=[n_worker_address])

    while len(s.workers) > 2:
        yield gen.sleep(0.01)

    total = c.submit(sum, futures, workers=a.address)
    yield total

    assert not a.has_what.get(n_worker_address)
    assert not any(n_worker_address in s for s in a.who_has.values())

    yield n._close()
開發者ID:tomMoral,項目名稱:distributed,代碼行數:33,代碼來源:test_failed_workers.py

示例4: create_and_destroy_worker

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
    def create_and_destroy_worker(delay):
        start = time()
        while time() < start + 5:
            n = Nanny(s.address, ncores=2, loop=s.loop)
            n.start(0)

            yield gen.sleep(delay)

            yield n._close()
            print("Killed nanny")
開發者ID:tomMoral,項目名稱:distributed,代碼行數:12,代碼來源:test_stress.py

示例5: test_submit_after_failed_worker_async

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
def test_submit_after_failed_worker_async(c, s, a, b):
    n = Nanny(s.ip, s.port, ncores=2, loop=s.loop)
    n.start(0)
    while len(s.workers) < 3:
        yield gen.sleep(0.1)

    L = c.map(inc, range(10))
    yield wait(L)

    s.loop.add_callback(n.kill)
    total = c.submit(sum, L)
    result = yield total
    assert result == sum(map(inc, range(10)))

    yield n._close()
開發者ID:tomMoral,項目名稱:distributed,代碼行數:17,代碼來源:test_failed_workers.py

示例6: test_broken_worker_during_computation

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
def test_broken_worker_during_computation(c, s, a, b):
    s.allowed_failures = 100
    n = Nanny(s.ip, s.port, ncores=2, loop=s.loop)
    n.start(0)

    start = time()
    while len(s.ncores) < 3:
        yield gen.sleep(0.01)
        assert time() < start + 5

    N = 256
    expected_result = N * (N + 1) // 2
    i = 0
    L = c.map(inc, range(N),
              key=['inc-%d-%d' % (i, j) for j in range(N)])
    while len(L) > 1:
        i += 1
        L = c.map(slowadd, *zip(*partition_all(2, L)),
                  key=['add-%d-%d' % (i, j) for j in range(len(L) // 2)])

    yield gen.sleep(random.random() / 20)
    with ignoring(CommClosedError):  # comm will be closed abrupty
        yield c._run(os._exit, 1, workers=[n.worker_address])

    yield gen.sleep(random.random() / 20)
    while len(s.workers) < 3:
        yield gen.sleep(0.01)

    with ignoring(CommClosedError, EnvironmentError):  # perhaps new worker can't be contacted yet
        yield c._run(os._exit, 1, workers=[n.worker_address])

    [result] = yield c.gather(L)
    assert isinstance(result, int)
    assert result == expected_result

    yield n._close()
開發者ID:tomMoral,項目名稱:distributed,代碼行數:38,代碼來源:test_failed_workers.py

示例7: _create_worker

# 需要導入模塊: from distributed import Nanny [as 別名]
# 或者: from distributed.Nanny import start [as 別名]
 def _create_worker(self):
     worker = Worker(scheduler_ip=self.ip,
                     scheduler_port=self.port,
                     ncores=1)
     worker.start(0)
     return worker
開發者ID:Kobzol,項目名稱:pyqit,代碼行數:8,代碼來源:distributedcontext.py


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