Comments (2)
Hi @lightbaseio,
It's possible but this will require some/a lot of wrapping. You need to extend python using CPython and there call any Go function exposed to C. You can't just pass a Go pointer and use it in Python.
In the datadog-agent we don't use this repo (because we want to embed both Python2 and Python3 at the same time, so we need to open shared library dynamically). But you can look into it to get some idea on how to do this.
rtloader
is the C bridge between Go and Python: it embed AND extend Python. rtloader/common is where we extend python. For example the python function datadog_agent.get_version
is created here https://github.com/DataDog/datadog-agent/blob/master/rtloader/common/builtins/datadog_agent.c#L42. We then call a callback here, that callback is actually a Go function exported to C (the agent at startup init all the callbacks).
We then export Go function to C here for example and init the C callback here.
As you can see embedding python is easy in Go, extending it requires some works.
In you example, I think, the simplest solution would be to create a Python Callable class, that internally store a C pointer and call a C method with that pointer when being called. Then in C you will actually call the Go function.
from go-python3.
Thanks for the explanation. My C is rusty but the code makes sense. Will give it a go when I have time!
from go-python3.
Related Issues (20)
- python3.PyImport_ImportModule(name) will emit a fatal error when called the second time. HOT 5
- How do I create an Object HOT 2
- fatal error: Python.h: No such file or directory #include "Python.h" HOT 4
- get PyObject's refcount
- Error: C.PyEval_ReInitThreads
- could not determine kind of name for C.PyImport_GetModule HOT 2
- How to stop or terminate python execution? HOT 1
- Hi, How to capture function return when use python3.PyRun_AnyFile HOT 2
- could not determine kind of name for C.PyDict_ClearFreeList HOT 16
- PyEval_ReInitThreads removed since python 3.8 HOT 2
- build error on debian HOT 6
- Undefined reference to 'Py_True' HOT 4
- No module named xxx problem ,when the xxx is a so file .. HOT 2
- How could I Pass parameters from the Go side to the python file? HOT 2
- run on windows HOT 3
- SyntaxError: invalid syntax (uuid.py, line 138) HOT 1
- PyList_Insert and PyList_Append functions has an extra b HOT 2
- Goroutine calls Python but deadlocks HOT 2
- how can i use tensorflow with library HOT 2
- How do I create a Python bytes object HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-python3.