| 1 |
""" |
| 2 |
This script was run to produce some of the screenshots on https://docs.dask.org/en/stable/dashboard.html |
| 3 |
""" |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
import time |
| 8 |
|
| 9 |
from dask import delayed |
| 10 |
from dask.distributed import Client, wait |
| 11 |
|
| 12 |
|
| 13 |
@delayed |
| 14 |
def inc(x): |
| 15 |
time.sleep(0.1) |
| 16 |
return x + 1 |
| 17 |
|
| 18 |
|
| 19 |
@delayed |
| 20 |
def double(x): |
| 21 |
time.sleep(0.1) |
| 22 |
return 2 * x |
| 23 |
|
| 24 |
|
| 25 |
@delayed |
| 26 |
def add(x, y): |
| 27 |
time.sleep(0.1) |
| 28 |
return x + y |
| 29 |
|
| 30 |
|
| 31 |
if __name__ == "__main__": |
| 32 |
with Client(n_workers=4, threads_per_worker=2, memory_limit="4 GiB") as client: |
| 33 |
while True: |
| 34 |
data = list(range(1000)) |
| 35 |
output = [] |
| 36 |
for x in data: |
| 37 |
a = inc(x) |
| 38 |
b = double(x) |
| 39 |
c = add(a, b) |
| 40 |
output.append(c) |
| 41 |
|
| 42 |
total = delayed(sum)(output) |
| 43 |
total = total.persist() |
| 44 |
wait(total) |
| 45 |
time.sleep(5) |
| 46 |
del total |
| 47 |
time.sleep(2) |