forked from lithops-cloud/lithops
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserialize_futures.py
More file actions
35 lines (26 loc) · 792 Bytes
/
serialize_futures.py
File metadata and controls
35 lines (26 loc) · 792 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
30
31
32
33
34
35
"""
This example show how a lithops function can be invoked
in one machine and get the results in another machine by
simply serializing and passing the futures.
"""
import time
import os
# ---------------------- Machine 1 ---------------------
import lithops
import pickle
def my_map_function(id, x):
print(f"I'm activation number {id}")
return x + 7
fexec = lithops.FunctionExecutor()
futures = fexec.map(my_map_function, range(5))
with open('futures.pickle', 'wb') as file:
pickle.dump(futures, file)
time.sleep(5)
# ---------------------- Machine 2---------------------
import pickle
from lithops.wait import get_result
with open('futures.pickle', 'rb') as file:
futures = pickle.load(file)
results = get_result(futures)
print(results)
os.remove('futures.pickle')