unwanted writing to history.sqlite

46 views
Skip to first unread message

Ralf Hemmecke

unread,
Sep 15, 2025, 8:49:33 AMSep 15
to sage-devel
I have a number of files that I generate from a Makefile and then pass
each of their names to a shell with content

cat $1 | sage -q | sed 's/^sage: //'

That seems to work fine when I just call "make", but with "make -j12"
(there are then several instances of sage running and) I see the error
below.

Clearly, that comes from IPython wanting to save the input history.
In my situation history saving is useless and unwanted. I need some hint
to switch that off. Is this possible by adding some command(s) to the
file $1 or can I simply give a particular option to sage to avoid
writing to history.sqlite?

Thank you in advance
Ralf


====================================

[SageTerminalApp] ERROR | Failed to create history session in
/home/hemmecke/.sage/ipython-5.0.0/profile_default/history.sqlite.
History will not be saved.
Traceback (most recent call last):
File
"/zvol/sage/sage-10.4/x86_64/local/var/lib/sage/venv-python3.12.4/lib/python3.12/site-packages/IPython/core/history.py",
line 549, in __init__
self.new_session()
File
"/zvol/sage/sage-10.4/x86_64/local/var/lib/sage/venv-python3.12.4/lib/python3.12/site-packages/decorator.py",
line 232, in fun
return caller(func, *(extras + args), **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/zvol/sage/sage-10.4/x86_64/local/var/lib/sage/venv-python3.12.4/lib/python3.12/site-packages/IPython/core/history.py",
line 60, in only_when_enabled
return f(self, *a, **kw)
^^^^^^^^^^^^^^^^^
File
"/zvol/sage/sage-10.4/x86_64/local/var/lib/sage/venv-python3.12.4/lib/python3.12/site-packages/IPython/core/history.py",
line 574, in new_session
cur = conn.execute(
^^^^^^^^^^^^^
sqlite3.OperationalError: database is locked

Michael Orlitzky

unread,
Sep 15, 2025, 9:26:16 AMSep 15
to 'Ralf Hemmecke' via sage-devel
On 2025-09-15 14:49:21, 'Ralf Hemmecke' via sage-devel wrote:
> I have a number of files that I generate from a Makefile and then pass
> each of their names to a shell with content
>
> cat $1 | sage -q | sed 's/^sage: //'
>
> That seems to work fine when I just call "make", but with "make -j12"
> (there are then several instances of sage running and) I see the error
> below.
>
> Clearly, that comes from IPython wanting to save the input history.
> In my situation history saving is useless and unwanted. I need some hint
> to switch that off. Is this possible by adding some command(s) to the
> file $1 or can I simply give a particular option to sage to avoid
> writing to history.sqlite?

I recently closed this because it just went away for me at some point:

https://github.com/sagemath/sage/issues/33025

I think the locking got smarter, but it can probably never be good
enough to handle a large number of sessions started at once and
running simultaneously.

In general I would suggest using plain python files rather than a sage
shell session for input. For example,

#!/usr/bin/python3
from sage.all import *
print(ZZ(1) + ZZ(1))

which can then be run with "sage -python" or (if you are using your
distro's sage, or have installed it using meson/pip) just "python".

Using sage as a python library avoids the ipython history entirely,
but the big downside is that you can't use any of the magic sage shell
preparsing. So x^2 isn't exponentiation, and the 2 is a python int
rather than a Sage integer -- if you naively try to pipe in a sage
shell session, it's unlikely to work.

If that isn't feasible, another option would be to use a different
DOT_SAGE for each process. If it doesn't break anything else, that
will give each process its own history file. Something like,

DOT_SAGE=$(mktemp -d) sage ...

Ralf Hemmecke

unread,
Sep 15, 2025, 9:40:33 AMSep 15
to sage-...@googlegroups.com
On 9/15/25 15:26, Michael Orlitzky wrote:
> In general I would suggest using plain python files rather than a sage
> shell session for input. For example,
>
> #!/usr/bin/python3
> from sage.all import *
> print(ZZ(1) + ZZ(1))
>
> which can then be run with "sage -python" or (if you are using your
> distro's sage, or have installed it using meson/pip) just "python".

Oh, that sounds like a good idea.

> Using sage as a python library avoids the ipython history entirely,
> but the big downside is that you can't use any of the magic sage shell
> preparsing.

Hmmmm, I think that I would like to have preparsing. Since I generate my
input files anyway ... is there perhaps a python script that does the
translation for me?

Thank you
Ralf

Dima Pasechnik

unread,
Sep 15, 2025, 10:05:53 AMSep 15
to sage-...@googlegroups.com, Ralf Hemmecke
there is a Python function for this:

$ python
Python 3.13.5 (main, Jul 15 2025, 09:22:39) [GCC 14.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.all import preparse
>>> preparse("2^5")
'Integer(2)**Integer(5)'
>>>

HTH
Dima

>
> Thank you
> Ralf
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sage-devel/8deda600-4515-4082-bf8b-91e193108f5d%40gmail.com.

TB

unread,
Sep 17, 2025, 1:13:00 PMSep 17
to sage-...@googlegroups.com
On 15/09/2025 17:04, Dima Pasechnik wrote:
> On Mon, Sep 15, 2025 at 8:40 AM Ralf Hemmecke <hemm...@gmail.com> wrote:
>>
>> On 9/15/25 15:26, Michael Orlitzky wrote:
>>> In general I would suggest using plain python files rather than a sage
>>> shell session for input. For example,
>>>
>>> #!/usr/bin/python3
>>> from sage.all import *
>>> print(ZZ(1) + ZZ(1))
>>>
>>> which can then be run with "sage -python" or (if you are using your
>>> distro's sage, or have installed it using meson/pip) just "python".
>>
>> Oh, that sounds like a good idea.
>>
>>> Using sage as a python library avoids the ipython history entirely,
>>> but the big downside is that you can't use any of the magic sage shell
>>> preparsing.
>>
>> Hmmmm, I think that I would like to have preparsing. Since I generate my
>> input files anyway ... is there perhaps a python script that does the
>> translation for me?
>
> there is a Python function for this:
>
> $ python
> Python 3.13.5 (main, Jul 15 2025, 09:22:39) [GCC 14.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from sage.all import preparse
>>>> preparse("2^5")
> 'Integer(2)**Integer(5)'

Another option is the command

sage --preparse file1.sage file2.sage [...]

that generates the preparsed files file1.sage.py, file2.sage.py, etc.
It calls src/bin/sage-preparse, and for other scenarios, you might want
to check
https://doc.sagemath.org/html/en/reference/repl/sage/repl/preparse.html

Regards,
TB
Reply all
Reply to author
Forward
0 new messages