Skip to content

Commit e8ac6fc

Browse files
committed
Lazy init of host interface
1 parent 7cd425a commit e8ac6fc

File tree

4 files changed

+20
-164
lines changed

4 files changed

+20
-164
lines changed

cfaasm/tester.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

pyfaasm/core

-95.2 MB
Binary file not shown.

pyfaasm/pyfaasm/core.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_host_interface = None
2525

2626

27-
def init_host_interface():
27+
def _init_host_interface():
2828
global _host_interface
2929

3030
if _host_interface is None:
@@ -48,6 +48,7 @@ def set_local_input_output(value):
4848

4949

5050
def read_input():
51+
_init_host_interface()
5152
return _host_interface.__faasm_read_input()
5253

5354

@@ -56,6 +57,7 @@ def write_output(output):
5657
global output_data
5758
output_data = output
5859
else:
60+
_init_host_interface()
5961
_host_interface.__faasm_write_output(output)
6062

6163

@@ -70,10 +72,12 @@ def get_output():
7072

7173

7274
def read_state_size(key):
75+
_init_host_interface()
7376
return _host_interface.__faasm_read_state(bytes(key, "utf-8"), None, 0)
7477

7578

7679
def read_state(key, state_len):
80+
_init_host_interface()
7781
state_len = int(state_len)
7882
buff = ctypes.create_string_buffer(state_len)
7983
_host_interface.__faasm_read_state(bytes(key, "utf-8"), buff, state_len)
@@ -82,6 +86,7 @@ def read_state(key, state_len):
8286

8387

8488
def read_state_offset(key, total_len, offset, offset_len):
89+
_init_host_interface()
8590
total_len = int(total_len)
8691
offset_len = int(offset_len)
8792
buff = ctypes.create_string_buffer(offset_len)
@@ -93,10 +98,12 @@ def read_state_offset(key, total_len, offset, offset_len):
9398

9499

95100
def write_state(key, value):
101+
_init_host_interface()
96102
_host_interface.__faasm_write_state(bytes(key, "utf-8"), value, len(value))
97103

98104

99105
def write_state_offset(key, total_len, offset, value):
106+
_init_host_interface()
100107
offset = int(offset)
101108
total_len = int(total_len)
102109

@@ -106,14 +113,17 @@ def write_state_offset(key, total_len, offset, value):
106113

107114

108115
def push_state(key):
116+
_init_host_interface()
109117
_host_interface.__faasm_push_state(bytes(key, "utf-8"))
110118

111119

112120
def push_state_partial(key):
121+
_init_host_interface()
113122
_host_interface.__faasm_push_state_partial(bytes(key, "utf-8"))
114123

115124

116125
def pull_state(key, state_len):
126+
_init_host_interface()
117127
state_len = int(state_len)
118128
_host_interface.__faasm_pull_state(bytes(key, "utf-8"), state_len)
119129

@@ -124,7 +134,9 @@ def chain(func, input_data):
124134
func(input_data)
125135
return 0
126136
else:
127-
# Call native
137+
# Call into host interface
138+
_init_host_interface()
139+
128140
func_name = func.__name__
129141
return _host_interface.__faasm_chain_py(
130142
bytes(func_name, "utf-8"), input_data, len(input_data)
@@ -133,14 +145,16 @@ def chain(func, input_data):
133145

134146
def await_call(call_id):
135147
if PYTHON_LOCAL_CHAINING:
136-
# Calls are run immediately
148+
# Calls are run immediately in local chaining
137149
return 0
138150
else:
139-
# Call native
151+
_init_host_interface()
140152
return _host_interface.__faasm_await_call(call_id)
141153

142154

143155
def set_emulator_message(message_json):
156+
_init_host_interface()
157+
144158
message_bytes = bytes(message_json, "utf-8")
145159
if PYTHON_LOCAL_OUTPUT:
146160
global output_data
@@ -150,8 +164,10 @@ def set_emulator_message(message_json):
150164

151165

152166
def set_emulator_status(success):
167+
_init_host_interface()
153168
_host_interface.__set_emulator_status(success)
154169

155170

156171
def get_emulator_async_response():
172+
_init_host_interface()
157173
return _host_interface.__get_emulator_async_response()

pyfaasm/tester.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pyfaasm.core import (
22
read_state,
33
read_state_offset,
4-
init_host_interface,
54
write_state,
65
write_state_offset,
76
push_state,
@@ -10,8 +9,6 @@
109
)
1110
import json
1211

13-
init_host_interface()
14-
1512
msg = {
1613
"user": "demo",
1714
"function": "echo",

0 commit comments

Comments
 (0)