Skip to content
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

finalizer may never be called #515

Closed
dpinol opened this issue Jun 26, 2024 · 2 comments · Fixed by #516
Closed

finalizer may never be called #515

dpinol opened this issue Jun 26, 2024 · 2 comments · Fixed by #516
Labels
enhancement New feature or request
Milestone

Comments

@dpinol
Copy link
Contributor

dpinol commented Jun 26, 2024

Is your feature request related to a problem? Please describe.
In Julia, it looks like finalizers are always called when exiting.
E.g., the following code always prints "hola".

mutable struct S
    a
end
function S()
    return finalizer(_->Core.println("hola"), S(3))
end
S()

However, if we wrap it with juliacall, the finalizer is never executed.

import juliacall
juliacall.Main.include("kk.jl")

Describe the solution you'd like
I'd like finalizers to always be executed

Describe alternatives you've considered
My current workaround is finishing with

juliacall.Main.GC.gc()

@dpinol dpinol added the enhancement New feature or request label Jun 26, 2024
@cjdoris
Copy link
Collaborator

cjdoris commented Jun 27, 2024

Ok yeah looks like I should call jl_atexit_hook to stop the Julia runtime when Python exits. https://github.com/JuliaLang/julia/blob/f3298ee5e2b08f633a6a313d094c732ff1ce7e85/src/init.c#L236

@cjdoris cjdoris added this to the features milestone Jun 27, 2024
@dpinol
Copy link
Contributor Author

dpinol commented Jul 1, 2024

thanks, @cjdoris what about #516 ?
I works with this

Main.seval(
            """ mutable struct S
                    a
                end;
                function S()
                    return finalizer(_->Core.println("works!!!"), S(3));
                end;
                S();
        """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants