microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.31k stars 1.18k forks source link

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

Open AbhinavAjitsaria opened 5 years ago

AbhinavAjitsaria commented 5 years ago

Environment data

Actual behavior

Expected behavior

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
luabud commented 5 years ago

Related to https://github.com/microsoft/vscode-python/issues/7206

eElor commented 5 years ago

I observe a similar problem on Windows:

Environment data

Expected behaviour

Actual behaviour

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