JupyterLab Extension: TerminalSession wait for command to complete then shutdown


I am writing a JupyterLab extension and currently have a command that runs a Python script.

I want to shutdown the new terminal session after running the command (presumably via session.shutdown) but if I uncomment that line in the code below, the session terminates prior to the command running/completing.

How can I achieve my intended behavior? Any help is appreciated!

execute: () => {
        .then(session => {
                type: "stdin",
                content: ['python3 /test.py\n']

            // session.shutdown();

Thanks in advance! :slight_smile:

IIRC session.shutdown returns a promise. You may want to either return that promise, or await it.