-
Notifications
You must be signed in to change notification settings - Fork 336
Closed
Description
As discussed with @rchiodo @karthiknadig
Scenario:
- User starts notebook
- Runs a cell
- ipykernel is not installed in current environment
- We prompt user to install ipykernel and user clicks ok
- The installer sends the
python -m pip install ipykernel
(or similar) to the terminal
https://github.com/microsoft/vscode-python/blob/5c3433b6364db03fadbf58010937b65a23d106e5/src/client/common/installer/moduleInstaller.ts#L45 - Installer completes and resolves.
- Calling code assumes
ipykernel
has been installed - We attempt to start notebook, and kaboom.
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 TerminalServiceterminalService.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 toexecInShell.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
Labels
No labels