同步操作将从 百度开源/incubator-Teaclave 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
permalink |
---|
/docs/functions-in-python |
The Teaclave platform provides a convenient way to register a customized function written in Python, and the function is interpreted at runtime in an isolated trusted execution environment (i.e., Intel SGX).
Here is an simple example of an echo function:
def entrypoint(argv):
assert argv[0] == 'message'
assert argv[1] is not None
return argv[1]
The entrypoint
function defined above is the "entrypoint" to executing the
function. It takes one argument which is a list of arguments of this echo
function. The return value of the entrypoint
function will be passed back to
the client.
::: tip NOTE
Note that the function arguments in key-value format passed from the platform
are flattened into a list. For example, the {"message": "Hello, Teaclave!"}
arguments will become "message"
(argv[0]
) and "Hello, Teaclave!"
(argv[1]
).
:::
Current Python executor (i.e., MesaPy) already supports many modules of the
original Python standard library such as marshal
, math
, binascii
,
itertools
, micronumpy
. You can find a full list of available modules in the
document of MesaPy for SGX.
Besides these modules for general computation, you may curious about doing file
I/O in customized Python function. We provides APIs to integrated with the
executor runtime to read/write files registered along with the task. You can
either open a file through the teaclave_open
function or with the teaclave
module like this:
# open input via built-in teaclave_open
with teaclave_open("input_file", "rb") as f:
line = f.readline()
# open input via teaclave module
from teaclave import open
with open("output_file", "wb") as f:
f.write("This message is from Mesapy!")
Either function will give an file
object in Python, you can use it to read
lines or write data. And the first argument is the key of the registered
input/output files.
You can learn more about advanced usages in the example of logistic regression in Python.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。