microsoft / vscode-python

Python extension for Visual Studio Code

Home Page:https://aka.ms/pvsc-marketplace

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run Selection/Line and Run File produce error when used consecutively

AbhinavAjitsaria opened this issue · comments

Environment data

  • VS Code version: 1.28.2
  • Extension version: 2018.9.1
  • OS and version: Ubuntu 18.04
  • Python version: 3.6.6
  • Type of virtual environment used : venv

Actual behavior

  • After 'Run Selection/Line in Python terminal' once, if 'Run Python File in terminal' is used, the command tries to execute in the ongoing interpreter session invoked by the first 'Run'

  • After 'Run File in Python terminal' once, if 'Run Selection/Line in terminal' is used, the command tries to execute in the open shell session invoked by the first 'Run' directly without invoking the interpreter first

Expected behavior

  • Run Selection/Line in Python terminal should invoke the Python interpreter first if the terminal is open and its state has changed since last Run.
  • Run python file in terminal should close Python interpreter if it is currently open

Steps to reproduce:

  1. Write a basic python program and Run Selection/Line in Terrminal.
  2. Immediately after Step 1, Run File in Terminal.
    The options can be done in reverse order too. It produces and error too.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

bootstrap-window.js:195 [uncaught exception]: TypeError: Cannot read property 'isWrapped' of undefined
onUnexpectedError @ bootstrap-window.js:195
(anonymous) @ bootstrap-window.js:38
emitOne @ events.js:116
emit @ events.js:211
window.onerror @ /usr/share/code/resources/electron.asar/renderer/init.js:147
i.globals.onerror @ workbench.main.js:sourcemap:1538
setTimeout (async)
Linkifier.linkifyRows @ Linkifier.ts:76
Terminal._queueLinkification @ Terminal.ts:1143
(anonymous) @ Terminal.ts:619
EventEmitter.emit @ EventEmitter.ts:74
Renderer._renderRows @ Renderer.ts:199
RenderDebouncer._innerRefresh @ RenderDebouncer.ts:49
(anonymous) @ RenderDebouncer.ts:40
requestAnimationFrame (async)
RenderDebouncer.refresh @ RenderDebouncer.ts:40
Renderer.refreshRows @ Renderer.ts:190
Terminal.refresh @ Terminal.ts:1132
Renderer.onIntersectionChange @ Renderer.ts:87
t._resize @ workbench.main.js:sourcemap:3549
t.layout @ workbench.main.js:sourcemap:3548
t.setVisible @ workbench.main.js:sourcemap:3542
(anonymous) @ workbench.main.js:sourcemap:3641
t.setVisible @ workbench.main.js:sourcemap:3641
(anonymous) @ workbench.main.js:sourcemap:3648
e.setActiveInstanceByIndex @ workbench.main.js:sourcemap:3648
e.setActiveInstance @ workbench.main.js:sourcemap:3647
e.$show @ workbench.main.js:sourcemap:3251
t._doInvokeHandler @ workbench.main.js:sourcemap:3267
t._invokeHandler @ workbench.main.js:sourcemap:3266
t._receiveRequest @ workbench.main.js:sourcemap:3265
t._receiveOneMessage @ workbench.main.js:sourcemap:3264
(anonymous) @ workbench.main.js:sourcemap:3262
e.fire @ workbench.main.js:sourcemap:181
a @ workbench.main.js:sourcemap:318
n._socketDataListener @ workbench.main.js:sourcemap:318
emitOne @ events.js:116
emit @ events.js:211
addChunk @ _stream_readable.js:263
readableAddChunk @ _stream_readable.js:250
Readable.push @ _stream_readable.js:208
onread @ net.js:594
bootstrap-window.js:198 TypeError: Cannot read property 'isWrapped' of undefined
    at Buffer.getWrappedRangeForLine (Buffer.ts:302)
    at BufferStringIterator.next (Buffer.ts:421)
    at Linkifier._linkifyRows (Linkifier.ts:101)
    at Linkifier.ts:76
onUnexpectedError @ bootstrap-window.js:198
(anonymous) @ bootstrap-window.js:38
emitOne @ events.js:116
emit @ events.js:211
window.onerror @ /usr/share/code/resources/electron.asar/renderer/init.js:147
i.globals.onerror @ workbench.main.js:sourcemap:1538
setTimeout (async)
Linkifier.linkifyRows @ Linkifier.ts:76
Terminal._queueLinkification @ Terminal.ts:1143
(anonymous) @ Terminal.ts:619
EventEmitter.emit @ EventEmitter.ts:74
Renderer._renderRows @ Renderer.ts:199
RenderDebouncer._innerRefresh @ RenderDebouncer.ts:49
(anonymous) @ RenderDebouncer.ts:40
requestAnimationFrame (async)
RenderDebouncer.refresh @ RenderDebouncer.ts:40
Renderer.refreshRows @ Renderer.ts:190
Terminal.refresh @ Terminal.ts:1132
Renderer.onIntersectionChange @ Renderer.ts:87
t._resize @ workbench.main.js:sourcemap:3549
t.layout @ workbench.main.js:sourcemap:3548
t.setVisible @ workbench.main.js:sourcemap:3542
(anonymous) @ workbench.main.js:sourcemap:3641
t.setVisible @ workbench.main.js:sourcemap:3641
(anonymous) @ workbench.main.js:sourcemap:3648
e.setActiveInstanceByIndex @ workbench.main.js:sourcemap:3648
e.setActiveInstance @ workbench.main.js:sourcemap:3647
e.$show @ workbench.main.js:sourcemap:3251
t._doInvokeHandler @ workbench.main.js:sourcemap:3267
t._invokeHandler @ workbench.main.js:sourcemap:3266
t._receiveRequest @ workbench.main.js:sourcemap:3265
t._receiveOneMessage @ workbench.main.js:sourcemap:3264
(anonymous) @ workbench.main.js:sourcemap:3262
e.fire @ workbench.main.js:sourcemap:181
a @ workbench.main.js:sourcemap:318
n._socketDataListener @ workbench.main.js:sourcemap:318
emitOne @ events.js:116
emit @ events.js:211
addChunk @ _stream_readable.js:263
readableAddChunk @ _stream_readable.js:250
Readable.push @ _stream_readable.js:208
onread @ net.js:594
Buffer.ts:302 Uncaught TypeError: Cannot read property 'isWrapped' of undefined
    at Buffer.getWrappedRangeForLine (Buffer.ts:302)
    at BufferStringIterator.next (Buffer.ts:421)
    at Linkifier._linkifyRows (Linkifier.ts:101)
    at Linkifier.ts:76
Buffer.getWrappedRangeForLine @ Buffer.ts:302
BufferStringIterator.next @ Buffer.ts:421
Linkifier._linkifyRows @ Linkifier.ts:101
(anonymous) @ Linkifier.ts:76
setTimeout (async)
Linkifier.linkifyRows @ Linkifier.ts:76
Terminal._queueLinkification @ Terminal.ts:1143
(anonymous) @ Terminal.ts:619
EventEmitter.emit @ EventEmitter.ts:74
Renderer._renderRows @ Renderer.ts:199
RenderDebouncer._innerRefresh @ RenderDebouncer.ts:49
(anonymous) @ RenderDebouncer.ts:40
requestAnimationFrame (async)
RenderDebouncer.refresh @ RenderDebouncer.ts:40
Renderer.refreshRows @ Renderer.ts:190
Terminal.refresh @ Terminal.ts:1132
Renderer.onIntersectionChange @ Renderer.ts:87
t._resize @ workbench.main.js:sourcemap:3549
t.layout @ workbench.main.js:sourcemap:3548
t.setVisible @ workbench.main.js:sourcemap:3542
(anonymous) @ workbench.main.js:sourcemap:3641
t.setVisible @ workbench.main.js:sourcemap:3641
(anonymous) @ workbench.main.js:sourcemap:3648
e.setActiveInstanceByIndex @ workbench.main.js:sourcemap:3648
e.setActiveInstance @ workbench.main.js:sourcemap:3647
e.$show @ workbench.main.js:sourcemap:3251
t._doInvokeHandler @ workbench.main.js:sourcemap:3267
t._invokeHandler @ workbench.main.js:sourcemap:3266
t._receiveRequest @ workbench.main.js:sourcemap:3265
t._receiveOneMessage @ workbench.main.js:sourcemap:3264
(anonymous) @ workbench.main.js:sourcemap:3262
e.fire @ workbench.main.js:sourcemap:181
a @ workbench.main.js:sourcemap:318
n._socketDataListener @ workbench.main.js:sourcemap:318
emitOne @ events.js:116
emit @ events.js:211
addChunk @ _stream_readable.js:263
readableAddChunk @ _stream_readable.js:250
Readable.push @ _stream_readable.js:208
onread @ net.js:594

Related to #7206

I observe a similar problem on Windows:

Environment data

  • VS Code version: 1.39.1 (user setup)
  • Extension version: 2019.10.41019
  • OS and version: Windows 10 64-bit
  • Python version: 3.7.4 (conda)
  • Type of virtual environment used: conda (base)
  • Jedi or Language Server?: python.jediEnabled: true

Expected behaviour

  • 'Run File in Python terminal' runs on cmd terminal.
  • 'Run Selection/Line in Python terminal' runs on Python REPL.
  • Each runs independently of previous run and in correct terminal.

Actual behaviour

  • Both commands run on terminal '2: Python'.
  • REPL only initializes once and does not close when 'Run File in Python terminal'.

1) 'Run File in Python terminal'

(OK)
terminal '2: Python' is created and

C:\Users\...>C:/Users/.../Miniconda3/Scripts/activate

(base) C:\Users\...>C:/Users/.../Miniconda3/python.exe "c:/Users/.../Documents/Python Scripts/hello.py"
hello

2) 'Run Selection/Line in Python terminal'

(OK)
REPL in terminal '2: Python' is initialized.

(base) C:\Users\...>C:/Users/.../Miniconda3/python.exe
Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello")
hello

3) Try again 'Run File in Python terminal'

(ERROR => in terminal '2: Python' REPL is still active!!!)

>>> C:/Users/.../Miniconda3/python.exe "c:/Users/.../Documents/Python Scripts/hello.py"
  File "<stdin>", line 1
    C:/Users/.../Miniconda3/python.exe "c:/Users/.../Documents/Python Scripts/hello.py"
      ^
SyntaxError: invalid syntax

selecting terminal '1: cmd' or opening new terminal does not work, since run jumps into '2: Python'.

4) Exit REPL manually

>>> exit()

(base) C:\Users\...>

5) 'Run File in Python terminal'

(OK)

(base) C:\Users\...>C:/Users/.../Miniconda3/python.exe "c:/Users/.../Documents/Python Scripts/hello.py"
hello 

6) 'Run Selection/Line in Python terminal'

(ERROR because of 3) => REPL is not initialized a second time.)

(base) C:\Users\...>print("hello")
Unable to initialize device PRN

Steps to reproduce:

'Run File in Python terminal' tests active terminal. 
        if REPL active:
            run in cmd terminal (which is already open in '1: cmd') 
'Run Selection/Line in Python terminal' tests active terminal.
        if '2: Python' selected and REPL active:
            run 
        else: 
            change to terminal '2: Python' 
            if REPL is not active in '2: Python':
                initialize REPL and run selection