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

PythonCall - Not all in-scope variables available with callback #312

Closed
bryaan opened this issue May 23, 2023 · 3 comments
Closed

PythonCall - Not all in-scope variables available with callback #312

bryaan opened this issue May 23, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@bryaan
Copy link

bryaan commented May 23, 2023

Affects: PythonCall

I don't have the ability to post the exact code that causes this to break. However it is a very strange issue that seems to be due to this library. I am using julia 1.9.0.

In the following code for some reason not all variables will be available in the callback. Changing the order of declaration doesn't seem to affect it. Nor does making the variable a global. The issue happens consistently and I'm not sure what can be done to debug.

pylib = pyimport("mypylib")

a, b = create()
x = Dates.Second(15)
nextGuiUpdateDateTime = 1
c = 5

function callback(p1, p2)
    @show a, x, c
    @show nextGuiUpdateDateTime # doesnt work
end
pylib.start_loop(callback)
@bryaan bryaan added the bug Something isn't working label May 23, 2023
@cjdoris
Copy link
Collaborator

cjdoris commented May 23, 2023

Sounds weird! I can't think of anything to suggest other than reduce it to a MWE.

@bryaan
Copy link
Author

bryaan commented May 23, 2023

I still have the code, may try that. But I worked around it by making the main program loop in julia. Now it occurs to me having the main loop in python may be an anti-pattern for this lib. It also has the disadvantage of making stack traces very long and deep in the pythoncall chain.

@bryaan
Copy link
Author

bryaan commented May 25, 2023

Yea I figured it out, was simply not putting global in front of a variable. Strange how the bug presented itself though. Maybe the julia devs will want to improve the warning system for that.

@bryaan bryaan closed this as completed May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants