-
Notifications
You must be signed in to change notification settings - Fork 751
Should Python.Runtime.Py.With use Runtime.None instead of new PyObject(Runtime.PyNone)? #1192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The proble with "delallocating None" has gone, after I have switched to my own implmetation of "Py.With" F# code: let inline pyWith(pyObj: PyObject, func: PyObject -> 'T) =
let mutable ptr: PyObject option = None // this is F# None, in C# implementation you can use ``null`` instead
let mutable ptr2: PyObject option = None // this is F# None
let mutable ptr3: PyObject option = None // this is F# None
let mutable ex : PythonException = null;
let mutable res : 'T option = None // this is F# None
try
let obj2: PyObject = pyObj.InvokeMethod("__enter__");
res <- Some <| func(obj2)
with
| :? PythonException as ex2 ->
ex <- ex2;
ptr <- Some <| PyObject ex.PyType
ptr2 <- Some <| PyObject ex.PyValue;
ptr3 <- Some <| PyObject ex.PyTB;
let toPyNoneIfEmpty(o: PyObject option) = o |> Option.defaultWith(fun () -> Runtime.GetPyNone()) // Runtime.GetPyNone() pythonnet_standard alternative of Py.None
let exitObject : PyObject = pyObj.InvokeMethod("__exit__", ptr |> toPyNoneIfEmpty, ptr |> toPyNoneIfEmpty, ptr2 |> toPyNoneIfEmpty, ptr3 |> toPyNoneIfEmpty);
if (ex |> isNull |> not && not <| exitObject.IsTrue()) then
raise ex
res |> Option.get |
@IvanAntipov this has already been fixed before 2.5.0 was released in #1062. The very link you provided to this repo has |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After long exectution (I train large ML model), I fall into
Fatal Python error: deallocating None
In my code I use Should Python.Runtime.Py.With method.
In this method I see PyNone to be used without increment of references count
As I undestand from stackoverflow each usage of None should increment Ref counter.
There is Python.Runtime.Runtime.None property
Should Runtime.None be used instead of Runtime.PyNone
Environment
The text was updated successfully, but these errors were encountered: