Reloading Script

Requirements

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:

../_images/ReloadingScript-light.svg ../_images/ReloadingScript-dark.svg

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);
}
  1. The code enters reloading script phase when it finds LIBYT_STOP file or an error occurred in inline functions.

  2. libyt starts reloading the script test_reload.py once RELOAD file is detected.

  3. 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 inside RELOAD_FAILED file. Either RELOAD_SUCCESS or RELOAD_FAILED will be generated.

  4. 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

Known Limitations