JupyterLab Extension: TerminalSession wait for command to complete then shutdown

#1

Hi!

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: () => {
    TerminalSession.startNew()
        .then(session => {
            session.send({
                type: "stdin",
                content: ['python3 /test.py\n']
            });

            // session.shutdown();
        });
}

Thanks in advance! :slight_smile:

#2

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