microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 293 forks source link

Cannot execute Run current cell for ~1s after I stop typing #9763

Open chmielcode opened 2 years ago

chmielcode commented 2 years ago

Applies To

What happened?

When I try to "Run current cell" just after I stop typing nothing happens.

To reproduce the problem place a new cell marker (#%%), start interactive window, wait for it to load, add another cell with any content...

#%%
1

...and finally press shift+enter (Jupyter: Run current cell) quickly (<~1s) after typing "1". It is enough to press backspace, type e.g. "2" and hit shift+enter to see it again.

Usually pressing shift+enter again after a small delay will work as intended, but sometimes it doesn't for another second or two or it sends whatever is before the current cursor position causing sytax errors.

To see the "whatever is before the current cursor position" behaviour repeat the steps mentioned above, but keep editing a string literal before pressing shift+enter.

#%%
"type here before pressing shift+enter"

I observe the same thing for small files with one cell only and large ones with thousands of lines of code and hunderds of cells. I tried to disable "Jupyter Keymap" extension and remove all other relevant "shift+enter" keybindings, but nothing worked.

It's been happening for a couple of weeks now and it's really hard for me to tell, which update (Python, Pylance, Jupyter or VSCode) introduced this bug. I encounter it multiple times every day and it forces me to read exception messages to find out whether it's my code's fault or I simply clicked shift+enter to quickly.

VS Code Version

1.66.2

Jupyter Extension Version

v2022.3.1000901801

Jupyter logs

Info 19:07:26: Adding hash for 46 = 2c93a441d4af with 1 lines
Info 19:07:26: Cancel all remaining cells true || Error || undefined
Info 19:07:26: Cancel pending cells
Info 19:07:26: Cell 46 executed with state Error

Coding Language and Runtime Version

Python 3.10.4

Language Extension Version (if applicable)

Python v2022.4.1

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

DonJayamanne commented 2 years ago

Thanks for filing this issue. I'm unable to repro this at my end. Please could you capture a screen recording of this and upload it. You could try using gifcap.dev or the like to capture a gif.

chmielcode commented 2 years ago

Recording 2022-04-25 at 20 18 14 I press shift+enter after I type "1" in each line in the first cell. With the second "1" I wasn't quick enough, so it actually executed the cell.

In the second cell i press shift+enter after every couple of characters (I hope you can see the short pauses) and then move the cursor a little bit to the left to get the unexpected syntax error.

daylinmorgan commented 2 years ago

I have encountered this as well. I also have an issue which might be related where I need to execute higher up cells to proceed.

Recording2022-04-26at17 33 18

>>>python -VV
Python 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:38:57) [GCC 10.3.0]
>>> code -v
1.66.2
dfd34e8260c270da74b5c2d86d61aee4b6d56977
x64
>>> code --list-extensions --show-versions | grep -E 'python|jupyter'
ms-python.python@2022.5.11161003
ms-python.vscode-pylance@2022.4.2
ms-toolsai.jupyter@2022.3.1000901801
ms-toolsai.jupyter-keymap@1.0.0
ms-toolsai.jupyter-renderers@1.0.6
chmielcode commented 2 years ago

I still can reproduce this bug with the latest release (Jupyter v2022.4.1001271738, VSCode 1.67).

About the unexpected syntax error after editing a string literal I've noticed, that just the last character is lost. Let's say I have already executed...

"""some  text"""

...then added "x" in the middle and quickly tried to execute the cell again.

"""some x text"""

The result will be:

  Input In [28]
    """some x text""
    ^
SyntaxError: incomplete input

So "" instead of """.

print("xx") -> print("xx"' etc.

chmielcode commented 2 years ago

No change with current vscode/jupyter/python releases.

daylinmorgan commented 2 years ago

@chmielcode Have you tried enabling code lens?

Seemingly with the code lens enable this isn't happening.

chmielcode commented 2 years ago

@daylinmorgan Unfortunately I see no difference with code lens enabled.

  1. Type "abc", but not press shift+enter too quickly.

    #%%
    "abc"

    'abc'

  2. Add space between b and c and immediately click shift+enter

    #%%
    "ab c"

    Input In [2] "ab c ^ SyntaxError: unterminated string literal (detected at line 2)

amunger commented 1 year ago

@chmielcode - are you still seeing this issue? No one on the team has experienced this but we can still try and look for race conditions that might cause this if it's still occurring

chmielcode commented 1 year ago

@amunger yes, still the same.