forked from lithops-cloud/lithops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_args_call_async.py
76 lines (59 loc) · 1.81 KB
/
multiple_args_call_async.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Simple Lithops examples using one single function invocation
with multiple parameters.
You can send multiple parameters to a single call function
writing them into a list. The parameters will be mapped in
the order you wrote them. In the following example the x
parameter will take the value 3 and the y parameter will
take the value 6.
"""
import lithops
def my_function(x, y):
return x + y
def sum_list(list_of_numbers):
total = 0
for num in list_of_numbers:
total = total+num
return total
def sum_list_mult(list_of_numbers, x):
total = 0
for num in list_of_numbers:
total = total+num
return total*x
if __name__ == "__main__":
args = (3, 6)
fexec = lithops.FunctionExecutor()
fexec.call_async(my_function, args)
print(fexec.get_result())
"""
The parameters can also be sent into a dictionary. In this
case you have to map them to the correct parameter of the
function as in the next example.
"""
kwargs = {'x': 2, 'y': 8}
fexec = lithops.FunctionExecutor()
fexec.call_async(my_function, kwargs)
print(fexec.get_result())
"""
If you want to send a list or a dict as a parameter of the
function, you must enclose them with [] as in the next
example.
"""
args = ([1, 2, 3, 4, 5], )
fexec = lithops.FunctionExecutor()
fexec.call_async(sum_list, args)
print(fexec.get_result())
"""
You can also send multiple parameters which include a list
"""
args = ([1, 2, 3, 4, 5], 5)
fexec = lithops.FunctionExecutor()
fexec.call_async(sum_list_mult, args)
print(fexec.get_result())
"""
Or alternatively
"""
kwargs = {'list_of_numbers': [1, 2, 3, 4, 5], 'x': 3}
fexec = lithops.FunctionExecutor()
fexec.call_async(sum_list_mult, kwargs)
print(fexec.get_result())