Reloading Script¶
Requirements¶
Compile
libyt
in interactive mode (-DINTERACTIVE_MODE=ON
).Call libyt API
yt_run_ReloadScript
.
Reloading Script¶
Reloading script feature is a file-based Interactive Python Prompt, such that user creates specific file to send instructions to libyt
and gets output from specific file.
How to Reload and Exit¶
The API:
int yt_run_ReloadScript(const char* flag_file, const char* reload, const char* script);
Below is the workflow:
A concrete example:
if (yt_run_ReloadScript("LIBYT_STOP", "RELOAD", "test_reload.py") != YT_SUCCESS) {
fprintf(stderr, "ERROR: yt_run_ReloadScript failed!\n");
exit(EXIT_FAILURE);
}
The code enters reloading script phase when it finds
LIBYT_STOP
file or an error occurred in inline functions.libyt
starts reloading the scripttest_reload.py
onceRELOAD
file is detected.If it successfully runs the script, the output will be inside
RELOAD_SUCCESS
file. If it failed to run the script, the output and error messages will be insideRELOAD_FAILED
file. EitherRELOAD_SUCCESS
orRELOAD_FAILED
will be generated.To exit, create
RELOAD_EXIT
in the folder.
Python Statements and libyt Defined Commands¶
The script can have both Python statements and libyt Defined Commands. We need to separate Python statements and libyt commands using #LIBYT_COMMANDS
. libyt commands should be after #LIBYT_COMMANDS
tag and commented out libyt defined commands.
For example:
import numpy as np
def func():
print("HELLO WORLD")
#LIBYT_COMMANDS
# %libyt status
# %libyt run func