gpt4 book ai didi

c++ - 使用 Python 和 C++ 进行实时处理和回调

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:29:25 24 4
gpt4 key购买 nike

我需要编写代码来进行一些计算上相当复杂的实时处理。我想创建一些 Python 类来管理我的所有脚本,并将算法的密集部分保留在 C++ 中编码,以便它们可以尽可能快地运行。我想在 Python 中实例化对象,并让 C++ 算法通过 Python 中的回调返回到脚本中。像这样的东西:

myObject = MyObject()
myObject.setCallback(myCallback)
myObject.run()

def myCallback(val):
"""Do something with the value passed back to the python script."""
pass

这可能吗?如何从在 C++ 模块中运行的循环在 python 中运行回调?谁有链接或教程来帮助我正确地做到这一点?

最佳答案

看看Boost.Python .其教程开始here .

关于c++ - 使用 Python 和 C++ 进行实时处理和回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2946226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com