本文整理汇总了Python中distributed.worker.Worker类的典型用法代码示例。如果您正苦于以下问题:Python Worker类的具体用法?Python Worker怎么用?Python Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Worker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_identity
def test_identity():
w = Worker('127.0.0.1', 8019)
ident = w.identity(None)
assert 'Worker' in ident['type']
assert ident['scheduler'] == 'tcp://127.0.0.1:8019'
assert isinstance(ident['ncores'], int)
assert isinstance(ident['memory_limit'], Number)
示例2: test_identity
def test_identity():
w = Worker('127.0.0.1', 8019)
ident = w.identity(None)
assert ident['type'] == 'Worker'
assert ident['scheduler'] == ('127.0.0.1', 8019)
assert isinstance(ident['ncores'], int)
assert isinstance(ident['memory_limit'], int)
示例3: f
def f():
c = Center('127.0.0.1')
c.listen(8007)
w = Worker(c.ip, c.port, ip='127.0.0.1')
yield w._start()
assert isinstance(w.port, int)
assert w.port > 1024
示例4: test_worker_with_port_zero
def test_worker_with_port_zero():
s = Scheduler()
s.listen(8007)
w = Worker(s.ip, s.port, ip='127.0.0.1')
yield w._start()
assert isinstance(w.port, int)
assert w.port > 1024
示例5: test_worker_death_timeout
def test_worker_death_timeout(s):
with dask.config.set({'distributed.comm.timeouts.connect': '1s'}):
yield s.close()
w = Worker(s.address, death_timeout=1)
yield w._start()
yield gen.sleep(2)
assert w.status == 'closed'
示例6: test_worker_with_port_zero
def test_worker_with_port_zero():
s = Scheduler()
s.start(8007)
w = Worker(s.address)
yield w._start()
assert isinstance(w.port, int)
assert w.port > 1024
yield w._close()
示例7: test_scheduler_file
def test_scheduler_file():
with tmpfile() as fn:
s = Scheduler(scheduler_file=fn)
s.start(8009)
w = Worker(scheduler_file=fn)
yield w._start()
assert set(s.workers) == {w.address}
yield w._close()
s.stop()
示例8: test_service_hosts_match_worker
def test_service_hosts_match_worker(s):
pytest.importorskip('bokeh')
from distributed.bokeh.worker import BokehWorker
services = {('bokeh', 0): BokehWorker}
for host in ['tcp://0.0.0.0', 'tcp://127.0.0.2']:
w = Worker(s.address, services=services)
yield w._start(host)
sock = first(w.services['bokeh'].server._http._sockets.values())
assert sock.getsockname()[0] == host.split('://')[1]
yield w._close()
示例9: test_Executor
def test_Executor(c, s):
with ThreadPoolExecutor(2) as e:
w = Worker(s.ip, s.port, executor=e)
assert w.executor is e
yield w._start()
future = c.submit(inc, 1)
result = yield future
assert result == 2
assert e._threads # had to do some work
yield w._close()
示例10: test_avoid_memory_monitor_if_zero_limit
def test_avoid_memory_monitor_if_zero_limit(c, s):
worker = Worker(s.address, loop=s.loop, memory_limit=0,
memory_monitor_interval=10)
yield worker._start()
assert type(worker.data) is dict
assert 'memory' not in worker.periodic_callbacks
future = c.submit(inc, 1)
assert (yield future) == 2
yield gen.sleep(worker.memory_monitor_interval / 1000)
yield c.submit(inc, 2) # worker doesn't pause
yield worker._close()
示例11: test_health
def test_health():
w = Worker('127.0.0.1', 8019)
d = w.host_health()
assert isinstance(d, dict)
d = w.host_health()
try:
import psutil
except ImportError:
pass
else:
assert 'disk-read' in d
assert 'disk-write' in d
assert 'network-recv' in d
assert 'network-send' in d
示例12: test_worker_fds
def test_worker_fds(s):
psutil = pytest.importorskip('psutil')
yield gen.sleep(0.05)
start = psutil.Process().num_fds()
worker = Worker(s.address, loop=s.loop)
yield worker._start()
yield gen.sleep(0.1)
middle = psutil.Process().num_fds()
start = time()
while middle > start:
yield gen.sleep(0.01)
assert time() < start + 1
yield worker._close()
start = time()
while psutil.Process().num_fds() > start:
yield gen.sleep(0.01)
assert time() < start + 0.5
示例13: test_spill_to_disk
def test_spill_to_disk(e, s):
np = pytest.importorskip('numpy')
w = Worker(s.ip, s.port, loop=s.loop, memory_limit=1000)
yield w._start()
x = e.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='x')
yield _wait(x)
y = e.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='y')
yield _wait(y)
assert set(w.data) == {x.key, y.key}
assert set(w.data.fast) == {x.key, y.key}
z = e.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='z')
yield _wait(z)
assert set(w.data) == {x.key, y.key, z.key}
assert set(w.data.fast) == {y.key, z.key}
assert set(w.data.slow) == {x.key}
yield x._result()
assert set(w.data.fast) == {x.key, z.key}
assert set(w.data.slow) == {y.key}
示例14: test_spill_to_disk
def test_spill_to_disk(c, s):
np = pytest.importorskip('numpy')
w = Worker(s.address, loop=s.loop, memory_limit=1200 / 0.6,
memory_pause_fraction=None, memory_spill_fraction=None)
yield w._start()
x = c.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='x')
yield wait(x)
y = c.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='y')
yield wait(y)
assert set(w.data) == {x.key, y.key}
assert set(w.data.fast) == {x.key, y.key}
z = c.submit(np.random.randint, 0, 255, size=500, dtype='u1', key='z')
yield wait(z)
assert set(w.data) == {x.key, y.key, z.key}
assert set(w.data.fast) == {y.key, z.key}
assert set(w.data.slow) == {x.key} or set(w.data.slow) == {x.key, y.key}
yield x
assert set(w.data.fast) == {x.key, z.key}
assert set(w.data.slow) == {y.key} or set(w.data.slow) == {x.key, y.key}
yield w._close()
示例15: g
def g():
c = Center('127.0.0.1', 8017)
c.listen(c.port)
a = Worker('127.0.0.1', 8018, c.ip, c.port, ncores=1)
yield a._start()
b = Worker('127.0.0.1', 8019, c.ip, c.port, ncores=1)
yield b._start()
while len(c.ncores) < 2:
yield gen.sleep(0.01)
try:
yield f(c, a, b)
finally:
with ignoring(Exception):
yield a._close()
with ignoring(Exception):
yield b._close()
c.stop()