Is there a way to pass additional arguments to `on_exit`?

My use case is as follows (shown in the mock-up code below). Upon exiting Prodigy in the command-line, I would like to do some things in on_exit. However, the things that need to be done in on_exit depend on two arguments which are generated dynamically dependent on the specific session and annotation project an annotator is in, so I can't hard code them. However, the current setup below will yield an error because the arguments are not passed to the on_exit function when it gets returned by custom_textcat_manual(). So I wonder if it is possible to pass those arguments into on_exit.

    dataset=("Dataset to save answers to", "positional", None, str),
    source=("Data to annotate (file path or '-' to read from standard input)", "positional", None, str),
    label=("Comma-separated label(s) to annotate or text file with one label per line", "option", "l", get_labels),
    view_id=("Annotation interface", "option", "v", str),
    exclusive=("Treat classes as mutually exclusive (if not set, an example can have multiple correct classes)", "flag", "E", bool)
def custom_textcat_manual(dataset, source, label, view_id="text", exclusive=False):
    if not label:"textcat.manual requires at least one --label", exits=1)
    labels = label
    print("LABELS", labels)
    stream = get_stream(source, rehash = True, dedup = True, input_key="text")

    Some code to get argument1 and argument2

    def on_exit(controller, argument1, argument2):
        Do some stuff with argument1 and argument2
    return {"dataset": dataset, 
            "view_id": view_id, 
            "stream": stream, 
            "on_exit": on_exit, 
            "config": { "labels": labels}}

Hi! I hope I understand your question correctly. Where are you expecting to pass in those arguments, argument1 and argument2, and how are you generating them?

The on_exit function is a callback function that is executed internally by Prodigy when you exit the server – so Prodigy can't know what to pass in there. It will pass in the controller, which gives you access to annotation settings and components that you can use to compute the results.

I solved the issue by making the two arguments/variables global arguments -- the values of them are then accessible inside on_exit.

1 Like