File: dashboard-progress-script.py

package info (click to toggle)
dask 2022.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,456 kB
  • sloc: python: 93,706; javascript: 1,893; makefile: 152; sh: 101
file content (44 lines) | stat: -rw-r--r-- 896 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
This script was run to produce some of the screenshots on https://docs.dask.org/en/stable/dashboard.html
"""
import time

from dask import delayed
from dask.distributed import Client, wait


@delayed
def inc(x):
    time.sleep(0.1)
    return x + 1


@delayed
def double(x):
    time.sleep(0.1)
    return 2 * x


@delayed
def add(x, y):
    time.sleep(0.1)
    return x + y


if __name__ == "__main__":
    with Client(n_workers=4, threads_per_worker=2, memory_limit="4 GiB") as client:
        while True:
            data = list(range(1000))
            output = []
            for x in data:
                a = inc(x)
                b = double(x)
                c = add(a, b)
                output.append(c)

            total = delayed(sum)(output)
            total = total.persist()
            wait(total)
            time.sleep(5)
            del total
            time.sleep(2)