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

Finalize Python runtime while shutting down Julia #603

Merged
merged 4 commits into from
Nov 4, 2018

Conversation

tkf
Copy link
Member

@tkf tkf commented Oct 28, 2018

closes JuliaPy/pyjulia#208

It's a bit scary to play with the shutdown process of two GCs. But it seems to work in simple tests...

src/PyCall.jl Outdated
@@ -98,9 +98,11 @@ it is equivalent to a `PyNULL()` object.
"""
ispynull(o::PyObject) = o.o == PyPtr_NULL

function pydecref_(o::Union{PyPtr,PyObject})
function pydecref_(o::Union{PyPtr,PyObject}) :: Nothing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the return value anywhere. So why not return nothing always?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems better to return something potentially useful (o), so that the result can be chained with some other function. Also, this way it mirrors pyincref. Why not just return o always?

@tkf
Copy link
Member Author

tkf commented Oct 28, 2018

There is a segfault in Julia 0.7... https://travis-ci.org/JuliaPy/PyCall.jl/jobs/447533492#L767

@tkf
Copy link
Member Author

tkf commented Oct 28, 2018

...which is apparently solved by going to non-closure (non-$) form of @cfunction (just a by-product of 0.6 support).

https://travis-ci.org/JuliaPy/PyCall.jl/builds/447551472

@tkf
Copy link
Member Author

tkf commented Oct 29, 2018

Re #603 (comment): I changed the return type of pydecref_ back to the original. (I was uncertain about returning an "unsafe" value from it. But I guess usage like pydecref_(pyobj).o = PyPtr_NULL could be useful and decref'ed value was already unsafe anyway before the PR.)

@stevengj stevengj merged commit 48d730f into JuliaPy:master Nov 4, 2018
@tkf tkf deleted the Py_Finalize branch November 4, 2018 13:30
JobJob added a commit to JobJob/PyCall.jl that referenced this pull request Nov 15, 2018
Basically icorporates changes introduced in JuliaPy#603
stevengj pushed a commit that referenced this pull request Nov 15, 2018
* Fix Segfault during finalization

Basically icorporates changes introduced in #603

* Fix typo
@carstenbauer
Copy link
Contributor

While resolving merge conflicts for #517, I found that the "atexit" tests from this PR are failing due to me having a startup.jl (which loads BenchmarkTools).

@stevengj
Copy link
Member

How does your startup.jl file affect the test?

@carstenbauer
Copy link
Contributor

It failed because it couldn't find BenchmarkTools. I assume

out = read(`$(Base.julia_cmd()) -e $script`, String)

doesn't take care of setting the currently used environment.

@tkf
Copy link
Member Author

tkf commented Jan 22, 2019

I should have used $(Base.julia_cmd()) --startup-file=no -e $script

@carstenbauer
Copy link
Contributor

carstenbauer commented Jan 22, 2019

Should I simply fix it in #517?

@tkf
Copy link
Member Author

tkf commented Jan 22, 2019

I'd appreciate if you do it.

@carstenbauer
Copy link
Contributor

Done.

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

Successfully merging this pull request may close these issues.

atexit does not work in python-jl
3 participants