Skip to content

Make cypari2 threadsafe #107

Open
@roed314

Description

@roed314

As discussed here, the update from Sage 9.2 to 9.3 caused new segmentation faults when running with threads, which we believe is related to the cypari upgrade. Here's an illustration of the problem just with cypari.

Python 3.9.5 (default, May  4 2021, 03:33:11) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cypari2
>>> pari = cypari2.Pari()
>>> pari.issquarefree(15)
1
>>> from concurrent.futures import ThreadPoolExecutor
>>> with ThreadPoolExecutor() as e:
...     j = e.submit(pari.issquarefree, 15)
... 
>>> j.result()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "cypari2/auto_instance.pxi", line 14650, in cypari2.pari_instance.Pari_auto.issquarefree
  File "cypari2/gen.pyx", line 4813, in cypari2.gen.objtogen
  File "cypari2/convert.pyx", line 561, in cypari2.convert.PyObject_AsGEN
cysignals.signals.SignalError: Segmentation fault

Traceback with gdb

0x00007ffff708788e in new_chunk (x=<optimized out>) at ../src/kernel/none/level1.h:125
125	../src/kernel/none/level1.h: Aucun fichier ou dossier de ce type.
(gdb) tb
Temporary breakpoint 1 at 0x7ffff708788e: file ../src/kernel/none/level1.h, line 125.
(gdb) bt
#0  0x00007ffff708788e in new_chunk (x=<optimized out>) at ../src/kernel/none/level1.h:125
#1  cgeti (x=<optimized out>) at ../src/kernel/none/level1.h:198
#2  __pyx_f_7cypari2_7convert_PyLong_AS_GEN (__pyx_v_x=__pyx_v_x@entry=0x7ffff7300af0)
    at cypari2/convert.c:3721
#3  0x00007ffff7088858 in __pyx_f_7cypari2_7convert_PyObject_AsGEN (__pyx_v_x=<optimized out>)
    at cypari2/convert.c:4151
#4  0x00007ffff5ff7fc6 in __pyx_f_7cypari2_3gen_objtogen (__pyx_v_s=0x7ffff7300af0, 
    __pyx_skip_dispatch=<optimized out>) at cypari2/gen.c:186911
#5  0x00007ffff6cd1b09 in __pyx_pf_7cypari2_13pari_instance_9Pari_auto_876issquarefree (
    __pyx_v_x=0x7ffff7300af0, __pyx_v_self=<optimized out>) at cypari2/pari_instance.c:100713
#6  0x00007ffff6d2c859 in __Pyx_CyFunction_CallMethod (kw=0x0, arg=0x7ffff71c8f40, 
    self=0x7ffff5e2b540, func=0x7ffff5cc7a00) at cypari2/pari_instance.c:250940
#7  __Pyx_CyFunction_CallAsMethod (kw=0x0, args=<optimized out>, func=0x7ffff5cc7a00)
    at cypari2/pari_instance.c:54373
#8  __Pyx_CyFunction_CallAsMethod (func=0x7ffff5cc7a00, args=<optimized out>, kw=0x0)
    at cypari2/pari_instance.c:54357

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions