Jupyter: Edits to code disappear/revert when PyCharm goes to the background
Today I installed Jupyter and managed, with difficulty, to get it working with PyCharm, as described in the relevant part of the PyCharm documentation.
However, it seems that sometimes when I edit the code in a code cell in my Jupyter notebook, and then switch to a different application on my computer, such as Chrome, the change disappears—the code reverts to how it was before I edited it. Once, it even resulted in losing a whole code cell I'd added, as well as an edit to another code cell. I have observed this with PyCharm's and Chrome's windows side-by-side: as soon as I click on Chrome, my edits disappear.
If I save the notebook before I switch apps, it doesn't revert. If I run the cell before switching, it at least sometimes reverts. The changes can also get reverted if I lock and then unlock Windows. However, this is all intermittent and difficult to reproduce. (If I notice a pattern to it, I'll come back here and add it.)
Also, sometimes when I switch to Chrome, PyCharm immediately comes back to the front, and I have to switch to Chrome a second time. There isn't perfect correlation between this and the code getting reverted, but they might be related.
I never noticed either bug before I started using Jupyter with PyCharm.
I'm using PyCharm Professional 2016.2.3, on Windows 7 Enterprise SP1, and here's my pip list output (inside my project virtualenv), which matches what's listed in PyCharm's settings (with the exceptions that PyCharm says pip is at version 9.0.0 and those starting with capital letters are listed first):
> pip list
colorama (0.3.7)
cycler (0.10.0)
decorator (4.0.10)
entrypoints (0.2.2)
ipykernel (4.5.0)
ipython (5.1.0)
ipython-genutils (0.1.0)
ipywidgets (5.2.2)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter (1.0.0)
jupyter-client (4.4.0)
jupyter-console (5.0.0)
jupyter-core (4.2.0)
MarkupSafe (0.23)
matplotlib (1.5.3)
mistune (0.7.3)
nbconvert (4.2.0)
nbformat (4.1.0)
notebook (4.2.3)
numpy (1.11.2)
pickleshare (0.7.4)
pip (7.1.0)
prompt-toolkit (1.0.8)
Pygments (2.1.3)
pyparsing (2.1.10)
python-dateutil (2.5.3)
pytz (2016.7)
pyzmq (16.0.0)
qtconsole (4.2.1)
setuptools (28.7.1)
simplegeneric (0.8.1)
six (1.10.0)
tornado (4.4.2)
traitlets (4.3.1)
wcwidth (0.1.7)
widgetsnbextension (1.2.6)
win-unicode-console (0.5)
ipywidgets, matplotlib, nbconvert, and widgetsnbextension are listed as outdated in PyCharm's settings (with the latest versions being 6.0.0.beta1, 2.0.0b4, 5.0.0b1, and 2.0.0b2 respectively), but both PyCharm and pip fail to update them (and pip fails to update itself, too, despite asking me to update it every time I use it). But I think these are two separate issues (refusing to install betas, a pip/virtualenv bug) from the code getting reverted.
Update: This may have something to do with Undo and Redo, which do very strange things (seemingly all both destructive and autosaving) in Jupyter notebooks.
Please sign in to leave a comment.
Please file issue with it to PyCharm issue tracker: https://youtrack.jetbrains.com/issues/PY, thank you.
Done :)
For anybody else who might have this problem and find this thread, the issue is here: https://youtrack.jetbrains.com/issue/PY-21335