FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/func/python/dict_state.py at main · faasm/python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
faasm
/
python
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
6
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
func
/
python
/
dict_state.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (38 loc) · 1.14 KB
Breadcrumbs
python
/
func
/
python
/
dict_state.py
Copy path
File metadata and controls
52 lines (38 loc) · 1.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
pickle
from
pyfaasm
.
core
import
(
read_state
,
read_state_size
,
write_state
,
chain
,
await_call
,
)
KEY_A
=
"dict_a"
KEY_B
=
"dict_b"
def
get_dict_from_state
(
key
):
dict_size
=
read_state_size
(
key
)
pickled_dict
=
read_state
(
key
,
dict_size
)
return
pickle
.
loads
(
pickled_dict
)
def
write_dict_to_state
(
key
,
dict_in
):
pickled_dict
=
pickle
.
dumps
(
dict_in
)
write_state
(
key
,
pickled_dict
)
# This function is chained
def
check_pickle
(
input_bytes
):
d
=
get_dict_from_state
(
KEY_A
)
d
[
"epsilon"
]
=
"zeta"
write_dict_to_state
(
KEY_B
,
d
)
def
faasm_main
():
# Write initial dictionary to state
dict_a
=
{
"alpha"
:
"beta"
,
"gamma"
:
"delta"
}
write_dict_to_state
(
KEY_A
,
dict_a
)
# Make the chained call
call_id
=
chain
(
check_pickle
,
b""
)
await_call
(
call_id
)
# Load from state again
dict_b
=
get_dict_from_state
(
KEY_B
)
# Check expectation
expected
=
{
"alpha"
:
"beta"
,
"gamma"
:
"delta"
,
"epsilon"
:
"zeta"
}
if
dict_b
!=
expected
:
print
(
"Expected {} but got {}"
.
format
(
expected
,
dict_b
))
exit
(
1
)
print
(
"Dictionary as expected: {}"
.
format
(
dict_b
))
return
0
Back
|
FazBrowse Home
|
New Git URL