Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/PyCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,22 @@ mutable struct PyObject
o::PyPtr # the actual PyObject*
function PyObject(o::PyPtr)
po = new(o)
finalizer(pydecref, po)
return po
finalizer(_pydecref_eventually, po)
end
end

# we can only call pydecref from the main thread. if we happen to hit
# GC from a different thread, add the finalizer back to the finalization
# queue to try again later when we'll eventually be on the main thread.
function _pydecref_eventually(po)
if Threads.threadid()==1
pydecref(po)
else
finalizer(_pydecref_eventually, po)
end
return nothing
end

PyPtr(o::PyObject) = getfield(o, :o)

"""
Expand Down
2 changes: 1 addition & 1 deletion src/pybuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mutable struct PyBuffer
b = new(Py_buffer(C_NULL, PyPtr_NULL, 0, 0,
0, 0, C_NULL, C_NULL, C_NULL, C_NULL,
C_NULL, C_NULL, C_NULL))
finalizer(pydecref, b)
finalizer(_pydecref_eventually, b)
return b
end
end
Expand Down