We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e54c4ee commit cb334caCopy full SHA for cb334ca
src/PyCall.jl
@@ -76,11 +76,26 @@ mutable struct PyObject
76
o::PyPtr # the actual PyObject*
77
function PyObject(o::PyPtr)
78
po = new(o)
79
- finalizer(pydecref, po)
+ finalizer(_pydecref_locked, po)
80
return po
81
end
82
83
84
+const PYDECREF_LOCK = ReentrantLock()
85
+
86
+function _pydecref_locked(po::PyObject)
87
+ if !islocked(PYDECREF_LOCK)
88
+ # If available, we lock and decref
89
+ lock(PYDECREF_LOCK) do
90
+ pydecref_(po)
91
+ end
92
+ else
93
+ # Add back to queue to be decref'd later
94
95
96
+ return nothing
97
+end
98
99
PyPtr(o::PyObject) = getfield(o, :o)
100
101
"""
0 commit comments