Reloading Script¶
Requirements¶
Compile
libytin 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_STOPfile or an error occurred in inline functions.libytstarts reloading the scripttest_reload.pyonceRELOADfile is detected.If it successfully runs the script, the output will be inside
RELOAD_SUCCESSfile. If it failed to run the script, the output and error messages will be insideRELOAD_FAILEDfile. EitherRELOAD_SUCCESSorRELOAD_FAILEDwill be generated.To exit, create
RELOAD_EXITin 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