Skip to content

Waiting for ipykernel to be installed in terminal #2626

@DonJayamanne

Description

@DonJayamanne

As discussed with @rchiodo @karthiknadig
Scenario:

Problem

  • installer code returns even before the installation has completed

Cause

  • We have no way to tell whether terminal/shell has completed executing our request

@int19h @karthiknadig Doesn't this sound familiar.

Proposed Solution

  • Create a new subclass class that overrides the existing sendCommand method in TerminalService terminalService.sendCommand(pythonPath, args);,
    • Fortunately we have a factory. So we can switch between the two in the factory class.
    • That's one place to make a simple decision
  • Ensure we have a generic Python file (~/pythonFiles/execInShell.py) as follows:
# Note: The command and arguments are hardcoded as a sample.
# These commands could be '/usr/desktop/bin/conda install ipykernel -y' or other

# print command to output in terminal so user can see what is being executed.
# These values will be passed as arguments to the file.
print('python -m pip install ipykernel')
try
    # Signal completion of command with success state
    open('started.log')

    subprocess.check_call(["python", "-m", "pip", "install", "ipykernel"], stdout=sys.stdout, stderr=sys.stderr)

    # Signal completion of command with success state
    open('success.log')
except:
    # Signal completion of command with error state
    open('error.log')
  • Next, send the command python <fully qualified path>/execInShell.py python -m pip install ipykernel to the terminal (all arguments passed to execInShell.py will be executed in subprocess.
    Note: Terminal is has already been activated (current behavior).
  • Extension code will use the files to check whether the process has started, completed.

Notes:

  • This allows us to send any script to the terminal and wait for it to run to completion.
  • E.g. python execInShell.py /usr/desktop/bin/conda install -n env1 ipykernel
  • E.g. python execInShell.py c:\wow\conda.exe install -n env1 ipykernel

Obviously the args will be escaped properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions