Skip to content

propertynames segfaults when called inside PythonCall.GIL.@lock region #751

@topolarity

Description

@topolarity
using Base.Threads
using PythonCall
o = Py(randn(3,3))
t = Threads.@spawn begin
    PythonCall.GIL.@lock begin
        println(Core.stderr, propertynames(o))
    end
end
PythonCall.GIL.@unlock wait(t)
julia +1.12 --project=. mwe.jl
    CondaPkg Found dev dependencies: /home/topolarity/repos/claude/PythonCall.jl/CondaPkg.toml
    CondaPkg Found dependencies: /home/topolarity/.julia/packages/CondaPkg/8GjrP/CondaPkg.toml
...
[127641] signal 11 (1): Segmentation fault
in expression starting at /home/topolarity/repos/claude/PythonCall.jl/mwe.jl:9
_PyInterpreterState_GET at /usr/local/src/conda/python-3.14.3/Include/internal/pycore_pystate.h:211 [inlined]
get_type_cache at /usr/local/src/conda/python-3.14.3/Objects/typeobject.c:868 [inlined]
_PyType_LookupStackRefAndVersion at /usr/local/src/conda/python-3.14.3/Objects/typeobject.c:5798 [inlined]
_PyType_LookupRefAndVersion at /usr/local/src/conda/python-3.14.3/Objects/typeobject.c:5784 [inlined]
_PyType_LookupRef at /usr/local/src/conda/python-3.14.3/Objects/typeobject.c:5896 [inlined]
_PyObject_LookupSpecial at /usr/local/src/conda/python-3.14.3/Objects/typeobject.c:2791
_dir_object at /usr/local/src/conda/python-3.14.3/Objects/object.c:2020 [inlined]
PyObject_Dir at /usr/local/src/conda/python-3.14.3/Objects/object.c:2052
PyObject_Dir at /home/topolarity/repos/claude/PythonCall.jl/src/C/pointers.jl:302 [inlined]
macro expansion at /home/topolarity/repos/claude/PythonCall.jl/src/Core/Py.jl:118 [inlined]
pydir at /home/topolarity/repos/claude/PythonCall.jl/src/Core/builtins.jl:191
#4 at /home/topolarity/repos/claude/PythonCall.jl/src/Core/Py.jl:297

The problem is that #677 assumes the main thread is the appropriate thread to run this on, but that's not true in general if you're using the GIL / doing true multi-threading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions