Skip to content

Commit

Permalink
sagemath#26968: add a doctest to catch ecl race in maxima init
Browse files Browse the repository at this point in the history
We run a new instance of sage in a subprocess to ensure maxima is
not already initialized. We use a temporary MAXIMA_USERDIR so its empty,
and we try to initialize maxima twice in parallel to entice the race.

This temporary dir is placed within `DOT_SAGE` so it is easy
to try different filesystems.

The bug triggers more frequently if `DOT_SAGE` is in a high
latency filesystem (e.g. sshfs on a non-local host).

The next commit introduces a workaround for the bug.
  • Loading branch information
tornaria committed Feb 25, 2023
1 parent 8f5bbd2 commit d2cc160
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/sage/interfaces/maxima_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@
sage: bar == foo
True
TESTS:
Check our workaround for a race in ecl works, see :trac:`26968`.
We use a temporary `MAXIMA_USERDIR` so it's empty; we place it
in `DOT_SAGE` since we expect it to have more latency than `/tmp`.
sage: import tempfile, subprocess
sage: tmpdir = tempfile.TemporaryDirectory(dir=DOT_SAGE)
sage: _ = subprocess.run(['sage', '-c', # long time
....: f'''
....: import os
....: os.environ["MAXIMA_USERDIR"] = "{tmpdir.name}"
....: if not os.fork():
....: import sage.interfaces.maxima_lib
....: else:
....: import sage.interfaces.maxima_lib
....: os.wait()
....: '''])
sage: tmpdir.cleanup()
"""

# ****************************************************************************
Expand Down

0 comments on commit d2cc160

Please sign in to comment.