-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expectedfree-threadingItems related to supporting free-threaded (a.k.a. "no-GIL") builds of CPythonItems related to supporting free-threaded (a.k.a. "no-GIL") builds of CPythonscipy._libuarrayItems related to the uarray backendItems related to the uarray backend
Milestone
Description
From @albanD's report in #20669 (comment):
Running with pydebug build as of two weeks ago and using ua_function, 1.15.0dev0 crashes on exit with
(null):0: _Py_NegativeRefcount: Assertion failed: object has negative ref count
<object at 0x2000e12e2b0 is freed>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: finalizing (tstate=0x00000000009bab80)
From @colesbury comment that 3.13t sets all module as being immortal, the explanation is that
scipy/scipy/_lib/_uarray/_uarray_dispatch.cxx
Line 1774 in 941d5b0
/* m_free= */ globals_free}; |
scipy/scipy/_lib/_uarray/_uarray_dispatch.cxx
Line 145 in 941d5b0
py_ref ua_function; |
When we get to static variable de-alloc, we end up calling the py_ref destructor
~py_ref() { Py_XDECREF(obj_); } |
Since the m_free not being called is not going to be fixed, I guess the right fix is to have the static variable have an owning reference to the py_obj but explicitly leak it (never call decref on it).
This would be the same treatment being applied to PyTorch's static variables in pytorch/pytorch#130341 and other places like https://github.com/pytorch/pytorch/blob/0b134c15cdf8cb4c2c7ffed1c2b6518de44382bf/torch/csrc/autograd/python_hook.cpp#L105
Metadata
Metadata
Assignees
Labels
defectA clear bug or issue that prevents SciPy from being installed or used as expectedA clear bug or issue that prevents SciPy from being installed or used as expectedfree-threadingItems related to supporting free-threaded (a.k.a. "no-GIL") builds of CPythonItems related to supporting free-threaded (a.k.a. "no-GIL") builds of CPythonscipy._libuarrayItems related to the uarray backendItems related to the uarray backend