File: dashboard-progress-script.py

package info (click to toggle)
dask 2024.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,024 kB
  • sloc: python: 105,182; javascript: 1,917; makefile: 159; sh: 88
file content (47 lines) | stat: -rw-r--r-- 933 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
45
46
47
"""
This script was run to produce some of the screenshots on https://docs.dask.org/en/stable/dashboard.html
"""

from __future__ import annotations

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)