sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.41k stars 474 forks source link

ipython/SQLite errors when running multiple sessions #33025

Open orlitzky opened 2 years ago

orlitzky commented 2 years ago

I pretty regularly run multiple sage instances. Today I tried it with 9.5.beta8 for the first time and got,

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.5.beta8, Release Date: 2021-12-12               │
│ Using Python 3.9.9. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
[SageTerminalApp] ERROR | Failed to create history session in /home/mjo/.sage/ipython-5.0.0/profile_default/history.sqlite. History will not be saved.
Traceback (most recent call last):
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/IPython/core/history.py", line 543, in __init__
    self.new_session()
  File "<decorator-gen-15>", line 2, in new_session
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/IPython/core/history.py", line 58, in needs_sqlite
    return f(self, *a, **kw)
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/IPython/core/history.py", line 568, in new_session
    cur = conn.execute("""INSERT INTO sessions VALUES (NULL, ?, NULL,
sqlite3.OperationalError: database is locked

Then upon exiting,

sage: exit
Exiting Sage (CPU time 0m0.41s, Wall time 0m1.44s).
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.9/lib/python3.9/site-packages/IPython/core/history.py", line 576, in end_session
    self.db.execute("""UPDATE sessions SET end=?, num_cmds=? WHERE
sqlite3.OperationalError: database is locked

I don't think we need to display that. Running multiple instances of something (like bash itself) that accesses a single history file has always been caveat emptor.

Component: user interface

Issue created by migration from https://trac.sagemath.org/ticket/33025

mkoeppe commented 2 years ago
comment:1

I've never seen this one. Is this a regression introduced by the most recent IPython upgrade?

orlitzky commented 2 years ago
comment:2

Replying to @mkoeppe:

I've never seen this one. Is this a regression introduced by the most recent IPython upgrade?

It seems the file is only locked during the execution of a statement. So if you run a long computation in one terminal, e.g.

sage: A = matrix.random(CDF, 500, sparse=True)
sage: I = matrix.identity(CDF, 500, sparse=True)
sage: A = A*A.conjugate_transpose() + I

and then open another terminal and run "sage", you'll get the error. I do that all the time (impatience is a top reason I open multiple sessions), so I think it's very likely that this is a regression.

mkoeppe commented 2 years ago
comment:3

I don't see anything relevant in https://ipython.readthedocs.io/en/stable/whatsnew/version7.html

mkoeppe commented 2 years ago
comment:4

I can't reproduce this with 9.5.beta8 on macOS

orlitzky commented 2 years ago
comment:5

I wiped my ~/.sage and the problem persists. It's not a huge deal, everything still works. It's just ugly.

orlitzky commented 2 years ago
comment:6

Looks like I'm not the only one, at least: https://github.com/ipython/ipython/issues/12202#issuecomment-990229531