-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
How to get a context when python is embedded in an application? #439
Comments
The However, we will probably never provide an API that would serve as an entry point for Python. I mean, if you write a little C program that links to
No, definitively not. This is an implementation detail (only on CPython). Other Python runtimes like GraalPy and PyPy won't have this variable. |
@KubaO Could you give an example of how you would like to use the API. So you have an embedded interpreter running. That interpreter can already itself load HPy modules. What are the other situations in which you would like to call C functions that call the embedded Python's C API? I can imagine that an embedded Python might provide a function that calls a callback and provides a context to it, or some other means to run functions with a context to interact with the embedded interpreter. |
There's quite a bit of code in KiCad that calls "into" Python interpreter from code that itself was not invoked from Python code.
C++ UI code calls into Python from various points, to invoke user scripts etc. It's a common pattern where Python is used for scripting. Pretty much every project that has a UI and uses Python for scripting would be doing that. |
@KubaO Thanks for the explanation. Perhaps for the embedding case we could provide a method that returns an opaque reference to the interpreter, and another method that can use that reference to request a temporary execution context. E.g.
The intention is that this would be very similar to executing a C extensions function from the interpreter. The section between CFFI added some support for embedding Python without directly exposing the C API -- https://cffi.readthedocs.io/en/latest/embedding.html. That might be a bit painful for porting though? It's more helpful for executing Python code than for calling the C API directly from outside the interpreter. |
My use case is not module development, but having a (currently) CPython interpreter embedded in the application. I'm using HPy so that in distant future a different Python implementation could be embedded.
How do I get the context to actually do something with HPy? Is
_HPyGetContext
the way to do it?I've seen #268 and it'd seem to imply that there's no such API. That's... wierd?
The text was updated successfully, but these errors were encountered: