Giter VIP home page Giter VIP logo

Comments (2)

hush-hush avatar hush-hush commented on July 30, 2024 1

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.

lightbaseio avatar lightbaseio commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.