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

Is there a systematic way to check whether julia code is called via JuliaCall versus normal Julia? #517

Open
schlichtanders opened this issue Jul 2, 2024 · 4 comments
Labels
question Further information is requested

Comments

@schlichtanders
Copy link
Contributor

motivation: build juliacode which has some specific behaviour when run via JuliaCall
reusing the same code simplifies the interface as well as the code size

@schlichtanders schlichtanders added the question Further information is requested label Jul 2, 2024
@cjdoris
Copy link
Collaborator

cjdoris commented Jul 7, 2024

There is no API for this. The only way I can think of is to first check if PythonCall is in Base.loaded_modules (or just import PythonCall) then check PythonCall.C.CTX.is_embedded which is true if you are in JuliaCall.

@cjdoris
Copy link
Collaborator

cjdoris commented Jul 7, 2024

(This is relying on internals of both Base and PythonCall.)

@cjdoris
Copy link
Collaborator

cjdoris commented Jul 7, 2024

Oh another way is to do exactly what PythonCall itself does: hasproperty(Base.Main, :__PythonCall_libptr) is true if you are in JuliaCall.

Again, this relies on internals.

@schlichtanders
Copy link
Contributor Author

thank you very much. Great that at least there is way which kind of works.
I guess it is fine for me to rely on internals for now.

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

No branches or pull requests

2 participants