本文整理汇总了Python中distributed.Executor类的典型用法代码示例。如果您正苦于以下问题:Python Executor类的具体用法?Python Executor怎么用?Python Executor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Executor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bokeh
def test_bokeh():
pytest.importorskip('bokeh')
try:
proc = Popen(['dscheduler'], stdout=PIPE, stderr=PIPE)
e = Executor('127.0.0.1:%d' % Scheduler.default_port)
while True:
line = proc.stderr.readline()
if b'Bokeh UI' in line:
break
start = time()
while True:
try:
for name in [socket.gethostname(), 'localhost', '127.0.0.1', get_ip()]:
response = requests.get('http://%s:8787/status/' % name)
assert response.ok
break
except:
sleep(0.1)
assert time() < start + 5
finally:
with ignoring(Exception):
e.shutdown()
with ignoring(Exception):
os.kill(proc.pid, signal.SIGINT)
示例2: test__futures_to_dask_bag
def test__futures_to_dask_bag(s, a, b):
import dask.bag as db
e = Executor((s.ip, s.port), start=False)
yield e._start()
L = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
futures = yield e._scatter(L)
rb = yield _futures_to_dask_bag(futures)
assert isinstance(rb, db.Bag)
assert rb.npartitions == len(L)
lb = db.from_sequence([1, 2, 3, 4, 5, 6, 7, 8, 9], npartitions=3)
exprs = [lambda x: x.map(lambda x: x + 1).sum(),
lambda x: x.filter(lambda x: x % 2)]
for expr in exprs:
local = expr(lb).compute(get=dask.get)
remote = e.compute(expr(rb))
remote = yield remote._result()
assert local == remote
yield e._shutdown()
示例3: test_with_data
def test_with_data(s, a, b):
ss = HTTPScheduler(s)
ss.listen(0)
e = Executor((s.ip, s.port), start=False)
yield e._start()
L = e.map(inc, [1, 2, 3])
L2 = yield e._scatter(['Hello', 'world!'])
yield _wait(L)
client = AsyncHTTPClient()
response = yield client.fetch('http://localhost:%s/memory-load.json' %
ss.port)
out = json.loads(response.body.decode())
assert all(isinstance(v, int) for v in out.values())
assert set(out) == {a.address_string, b.address_string}
assert sum(out.values()) == sum(map(sys.getsizeof,
[1, 2, 3, 'Hello', 'world!']))
response = yield client.fetch('http://localhost:%s/memory-load-by-key.json'
% ss.port)
out = json.loads(response.body.decode())
assert set(out) == {a.address_string, b.address_string}
assert all(isinstance(v, dict) for v in out.values())
assert all(k in {'inc', 'data'} for d in out.values() for k in d)
assert all(isinstance(v, int) for d in out.values() for v in d.values())
assert sum(v for d in out.values() for v in d.values()) == \
sum(map(sys.getsizeof, [1, 2, 3, 'Hello', 'world!']))
ss.stop()
yield e._shutdown()
示例4: test_read_text
def test_read_text(s, a, b):
pytest.importorskip('dask.bag')
import dask.bag as db
from dask.imperative import Value
e = Executor((s.ip, s.port), start=False)
yield e._start()
b = read_text(test_bucket_name, 'test/accounts', lazy=True,
collection=True, anon=True)
assert isinstance(b, db.Bag)
yield gen.sleep(0.2)
assert not s.tasks
future = e.compute(b.filter(None).map(json.loads).pluck('amount').sum())
result = yield future._result()
assert result == (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) * 100
text = read_text(test_bucket_name, 'test/accounts', lazy=True,
collection=False, anon=True)
assert all(isinstance(v, Value) for v in text)
text = read_text(test_bucket_name, 'test/accounts', lazy=False,
collection=False, anon=True)
assert all(isinstance(v, Future) for v in text)
yield e._shutdown()
示例5: test_avro
def test_avro(s, a, b):
e = Executor((s.ip, s.port), start=False)
yield e._start()
avro_files = {'/tmp/test/1.avro': avro_bytes,
'/tmp/test/2.avro': avro_bytes}
with make_hdfs() as hdfs:
for k, v in avro_files.items():
with hdfs.open(k, 'w') as f:
f.write(v)
assert hdfs.info(k)['size'] > 0
L = yield _read_avro('/tmp/test/*.avro', lazy=False)
assert isinstance(L, list)
assert all(isinstance(x, Future) for x in L)
results = yield e._gather(L)
assert all(isinstance(r, list) for r in results)
assert results[0][:5] == data[:5]
assert results[-1][-5:] == data[-5:]
L = yield _read_avro('/tmp/test/*.avro', lazy=True)
assert isinstance(L, list)
assert all(isinstance(x, Value) for x in L)
示例6: f
def f(c, a, b):
e = Executor((c.ip, c.port), start=False, loop=loop)
yield e._start()
x_dsk = {('x', i, j): np.random.random((3, 3)) for i in range(3)
for j in range(2)}
y_dsk = {('y', i, j): np.random.random((3, 3)) for i in range(2)
for j in range(3)}
x_futures = yield e._scatter(x_dsk)
y_futures = yield e._scatter(y_dsk)
dt = np.random.random(0).dtype
x_local = da.Array(x_dsk, 'x', ((3, 3, 3), (3, 3)), dt)
y_local = da.Array(y_dsk, 'y', ((3, 3), (3, 3, 3)), dt)
x_remote = da.Array(x_futures, 'x', ((3, 3, 3), (3, 3)), dt)
y_remote = da.Array(y_futures, 'y', ((3, 3), (3, 3, 3)), dt)
exprs = [lambda x, y: x.T + y,
lambda x, y: x.mean() + y.mean(),
lambda x, y: x.dot(y).std(axis=0),
lambda x, y: x - x.mean(axis=1)[:, None]]
for expr in exprs:
local = expr(x_local, y_local)
local_results = dask.get(local.dask, local._keys())
local_result = da.Array._finalize(local, local_results)
remote = expr(x_remote, y_remote)
remote_results = yield e._get(remote.dask, remote._keys())
remote_result = da.Array._finalize(remote, remote_results)
assert np.all(local_result == remote_result)
yield e._shutdown()
示例7: test_lazy_values
def test_lazy_values(s, a, b):
with make_hdfs() as hdfs:
data = b'a'
for i in range(3):
hdfs.mkdir('/tmp/test/data-%d' % i)
for j in range(2):
fn = '/tmp/test/data-%d/file-%d.csv' % (i, j)
with hdfs.open(fn, 'w', repl=1) as f:
f.write(data)
e = Executor((s.ip, s.port), start=False)
yield e._start()
values = read_bytes('/tmp/test/', hdfs=hdfs, lazy=True)
assert all(isinstance(v, Value) for v in values)
while not s.restrictions:
yield gen.sleep(0.01)
assert not s.dask
results = e.compute(*values, sync=False)
results = yield e._gather(results)
assert len(results) == 6
assert all(x == b'a' for x in results)
示例8: dont_test_dataframes
def dont_test_dataframes(s, a): # slow
pytest.importorskip('pandas')
n = 3000000
fn = '/tmp/test/file.csv'
with make_hdfs() as hdfs:
data = (b'name,amount,id\r\n' +
b'Alice,100,1\r\nBob,200,2\r\n' * n)
with hdfs.open(fn, 'w') as f:
f.write(data)
e = Executor((s.ip, s.port), start=False)
yield e._start()
futures = read_bytes(fn, hdfs=hdfs, delimiter=b'\r\n')
assert len(futures) > 1
def load(b, **kwargs):
assert b
from io import BytesIO
import pandas as pd
bio = BytesIO(b)
return pd.read_csv(bio, **kwargs)
dfs = e.map(load, futures, names=['name', 'amount', 'id'], skiprows=1)
dfs2 = yield e._gather(dfs)
assert sum(map(len, dfs2)) == n * 2 - 1
示例9: test_bokeh_non_standard_ports
def test_bokeh_non_standard_ports():
pytest.importorskip('bokeh')
try:
proc = Popen(['dscheduler',
'--port', '3448',
'--http-port', '4824',
'--bokeh-port', '4832'], stdout=PIPE, stderr=PIPE)
e = Executor('127.0.0.1:3448')
while True:
line = proc.stderr.readline()
if b'Bokeh UI' in line:
break
start = time()
while True:
try:
response = requests.get('http://localhost:4832/status/')
assert response.ok
break
except:
sleep(0.1)
assert time() < start + 5
finally:
with ignoring(Exception):
e.shutdown()
with ignoring(Exception):
os.kill(proc.pid, signal.SIGINT)
示例10: test__dask_array_collections
def test__dask_array_collections(s, a, b):
import dask.array as da
e = Executor((s.ip, s.port), start=False)
yield e._start()
x_dsk = {('x', i, j): np.random.random((3, 3)) for i in range(3)
for j in range(2)}
y_dsk = {('y', i, j): np.random.random((3, 3)) for i in range(2)
for j in range(3)}
x_futures = yield e._scatter(x_dsk)
y_futures = yield e._scatter(y_dsk)
dt = np.random.random(0).dtype
x_local = da.Array(x_dsk, 'x', ((3, 3, 3), (3, 3)), dt)
y_local = da.Array(y_dsk, 'y', ((3, 3), (3, 3, 3)), dt)
x_remote = da.Array(x_futures, 'x', ((3, 3, 3), (3, 3)), dt)
y_remote = da.Array(y_futures, 'y', ((3, 3), (3, 3, 3)), dt)
exprs = [lambda x, y: x.T + y,
lambda x, y: x.mean() + y.mean(),
lambda x, y: x.dot(y).std(axis=0),
lambda x, y: x - x.mean(axis=1)[:, None]]
for expr in exprs:
local = expr(x_local, y_local).compute(get=dask.get)
remote = e.compute(expr(x_remote, y_remote))
remote = yield remote._result()
assert np.all(local == remote)
yield e._shutdown()
示例11: test_no_divisions
def test_no_divisions(s, a, b):
e = Executor((s.ip, s.port), start=False)
yield e._start()
dfs = e.map(tm.makeTimeDataFrame, range(5, 10))
df = yield _futures_to_dask_dataframe(dfs)
assert not df.known_divisions
assert list(df.columns) == list(tm.makeTimeDataFrame(5).columns)
示例12: test_hostport
def test_hostport():
try:
proc = Popen(['dask-scheduler', '--no-bokeh',
'--host', '127.0.0.1:8978'],
stdout=PIPE, stderr=PIPE)
e = Executor('127.0.0.1:8978')
finally:
e.shutdown()
os.kill(proc.pid, signal.SIGINT)
示例13: test_read_bytes
def test_read_bytes(s, a, b):
e = Executor((s.ip, s.port), start=False)
yield e._start()
futures = read_bytes(test_bucket_name, prefix='test/', anon=True)
assert len(futures) >= len(files)
results = yield e._gather(futures)
assert set(results).issuperset(set(files.values()))
yield e._shutdown()
示例14: test_defaults
def test_defaults():
try:
proc = Popen(['dscheduler', '--no-bokeh'], stdout=PIPE, stderr=PIPE)
e = Executor('127.0.0.1:%d' % Scheduler.default_port)
response = requests.get('http://127.0.0.1:9786/info.json')
assert response.ok
assert response.json()['status'] == 'running'
finally:
e.shutdown()
os.kill(proc.pid, signal.SIGINT)
示例15: test_read_csv_with_names
def test_read_csv_with_names(s, a, b):
with make_hdfs() as hdfs:
e = Executor((s.ip, s.port), start=False)
yield e._start()
with hdfs.open('/tmp/test/1.csv', 'wb') as f:
f.write(b'name,amount,id\nAlice,100,1\nBob,200,2')
df = yield _read_csv('/tmp/test/*.csv', names=['amount', 'name'],
lineterminator='\n', lazy=False)
assert list(df.columns) == ['amount', 'name']
yield e._shutdown()