Bug in the SageMath 9.0 Kernel when launching Notebooks

58 views
Skip to first unread message

JokingReaper

unread,
May 18, 2020, 9:12:14 AM5/18/20
to sage-devel
Hello. I recently installed Sagemath 9.0, of 64 bits in a computer using "Linux Mint 19.3 Tricia" (using the Ubuntu Installer downloaded from here: http://sagemath.c3sl.ufpr.br/linux/64bit/index.html ) and it worked pretty well for the first couple of hours. However, I created a notebook using the command:

$ ./sage -notebook

and it worked fine for the first time I used the notebook, made calculations and created adequate plots, however, when I closed the notebook and tried to open it again, there was a message indicating that "There is no connection to the kernel". This happens even when the installation of SageMath is local to the machine I'm using. Adjoint to this message is the notebook itself.

I tried to reinstall the entire program but the bug is persistent.

Also, when sage is launched directly from terminal with the command

$ ./sage

there seems to be no problem, as the program works just fine.

I also switched to the Python kernel from the notebook and it seems to work fine, except of course that it doesn't have the same commands as the SageMath kernel.

The terminal in which I run the program generates this message:

------------------------------------------------------------------------------------------------------------------------------------------------------

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.0, Release Date: 2020-01-01                     │
│ Using Python 3.7.3. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
Please wait while the SageNB export server starts...
[I 07:57:21.925 NotebookApp] Using MathJax: nbextensions/mathjax/MathJax.js
[I 07:57:22.200 NotebookApp] Serving notebooks from local directory: /home/jokingreaper
[I 07:57:22.200 NotebookApp] The Jupyter Notebook is running at:
[I 07:57:22.200 NotebookApp] http://localhost:8888/?token=df2929c61c1567dbb49b58cfa8953f6f6c0ab84d8f078e75
[I 07:57:22.200 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 07:57:22.272 NotebookApp]
   
    To access the notebook, open this file in a browser:
        file:///run/user/1000/jupyter/nbserver-4714-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=df2929c61c1567dbb49b58cfa8953f6f6c0ab84d8f078e75
[I 07:57:54.301 NotebookApp] Kernel started: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1
/home/jokingreaper/SageMath/SageMath/local/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No module named 'sage.repl'; 'sage' is not a package)
[I 07:57:57.300 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
/home/jokingreaper/SageMath/SageMath/local/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No module named 'sage.repl'; 'sage' is not a package)
[I 07:58:00.316 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
/home/jokingreaper/SageMath/SageMath/local/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No module named 'sage.repl'; 'sage' is not a package)
[I 07:58:03.328 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
/home/jokingreaper/SageMath/SageMath/local/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No module named 'sage.repl'; 'sage' is not a package)
[I 07:58:06.336 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
/home/jokingreaper/SageMath/SageMath/local/bin/python3: Error while finding module specification for 'sage.repl.ipython_kernel' (ModuleNotFoundError: No module named 'sage.repl'; 'sage' is not a package)
[W 07:58:09.344 NotebookApp] KernelRestarter: restart failed
[W 07:58:09.345 NotebookApp] Kernel 9b4f0013-0d21-4710-aa9d-4db40af8e1d1 died, removing from map.
[W 07:58:15.717 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235
[W 07:58:37.784 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235
[W 07:58:54.716 NotebookApp] Timeout waiting for kernel_info reply from 9b4f0013-0d21-4710-aa9d-4db40af8e1d1
[E 07:58:54.719 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1)
[W 07:58:54.722 NotebookApp] 404 GET /api/kernels/9b4f0013-0d21-4710-aa9d-4db40af8e1d1/channels?session_id=3c87fec8a8c34a2a8bff058350ea3235 (127.0.0.1): Kernel does not exist: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1
[W 07:58:54.734 NotebookApp] 404 GET /api/kernels/9b4f0013-0d21-4710-aa9d-4db40af8e1d1/channels?session_id=3c87fec8a8c34a2a8bff058350ea3235 (127.0.0.1) 39020.31ms referer=None
[W 07:58:54.735 NotebookApp] 404 GET /api/kernels/9b4f0013-0d21-4710-aa9d-4db40af8e1d1/channels?session_id=3c87fec8a8c34a2a8bff058350ea3235 (127.0.0.1): Kernel does not exist: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1
[W 07:58:54.736 NotebookApp] 404 GET /api/kernels/9b4f0013-0d21-4710-aa9d-4db40af8e1d1/channels?session_id=3c87fec8a8c34a2a8bff058350ea3235 (127.0.0.1) 16954.20ms referer=None
[W 07:58:58.761 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235
[W 07:59:26.784 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235
[W 08:00:02.804 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235
[W 08:00:54.825 NotebookApp] Replacing stale connection: 9b4f0013-0d21-4710-aa9d-4db40af8e1d1:3c87fec8a8c34a2a8bff058350ea3235

------------------------------------------------------------------------------------------------------------------------------------------------------

Unfortunately I don't know how to fix this, And I would like some help on how to clean this.


First-Notebook.ipynb

JokingReaper

unread,
May 18, 2020, 10:13:06 AM5/18/20
to sage-devel
Apparently I found the problem... NEVER name a file "sage.py" in the same folder of the notebooks, it will only create a conflict with the package "sage" from SageMath, and think that the file "sage.py" is the package that must be used... don't know if there is a work-around this to warn users or if there is a way to tell the kernel to alway prioretize the file from it's source folder.

Nils Bruin

unread,
May 19, 2020, 12:07:58 PM5/19/20
to sage-devel
On Monday, May 18, 2020 at 7:13:06 AM UTC-7, JokingReaper wrote:
Apparently I found the problem... NEVER name a file "sage.py" in the same folder of the notebooks, it will only create a conflict with the package "sage" from SageMath, and think that the file "sage.py" is the package that must be used... don't know if there is a work-around this to warn users or if there is a way to tell the kernel to alway prioretize the file from it's source folder.

This is a "well-known" problem in python:


There is a "workaround" in python, but it's probably unworkable for other reasons: if you remove the empty string from sys.path, then the current directory is no longer part of the places where modules are searched, so under normal conditions, after:

import sys
sys.path.remove('')

your file sage.py would no longer be shadowing (all of!) sage. You'd have to find a way to ensure that this code is run before python tries to load sage, though.

It means, for one thing, that you should *NEVER* run a python program in an untrusted directory (where there may be unknown files shadowing whatever and/or someone may place files there unexpectedly), which can be complicated if a nice utility happens to be written in python. As the trick above shows, there are ways to harden python against this trap, but it's hard to do and easy to forget, so I expect it's usually neglected.

This is probably one of the most prominent tensions in python being both a scripting and an application language. The two functions would choose different priorities in features/traps like this, and here scripting has won ...
Reply all
Reply to author
Forward
0 new messages