forked from finos/opengris-scaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_client.py
More file actions
29 lines (22 loc) · 920 Bytes
/
nested_client.py
File metadata and controls
29 lines (22 loc) · 920 Bytes
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
"""This example shows how to created nested tasks. Please see graphtask_nested_client.py for more information."""
from scaler import Client
from scaler.cluster.combo import SchedulerClusterCombo
# Calculate fibonacci sequence with nested client.
# Each intermediate call in the recursive process is submitted to the client.
def fibonacci(client: Client, n: int):
if n == 0:
return 0
elif n == 1:
return 1
else:
a = client.submit(fibonacci, client, n - 1)
b = client.submit(fibonacci, client, n - 2)
return a.result() + b.result()
def main():
# For an explanation on how SchedulerClusterCombo and Client work, please see simple_client.py
cluster = SchedulerClusterCombo(n_workers=1)
client = Client(address=cluster.get_address())
result = client.submit(fibonacci, client, 8).result()
print(result) # 21
if __name__ == "__main__":
main()