C ++和Python之间的简单IPC(跨平台) [英] Simple IPC between C++ and Python (cross platform)
问题描述
我有一个在后台运行的C ++进程,会在同一个框架上运行的Python进程很少产生'事件'。
I have a C++ process running in the background that will be generating 'events' infrequently that a Python process running on the same box will need to pick up.
- C侧的代码需要尽可能轻量级。
- Python端是只读的。
- 实施必须跨平台。
- 发送的数据非常简单。
- The code on the C side needs to be as lightweight as possible.
- The Python side is read-only.
- The implementation must be cross-platform.
- The data being sent is very simple.
我的选项是什么?
感谢
推荐答案
zeromq - 没有别的。将消息编码为字符串。
zeromq -- and nothing else. encode the messages as strings.
但是,如果要从库中获取序列化,请使用 protobuf 它会为Python和C ++生成类。你在两端使用SerializeToString()和ParseFromString()函数,然后通过ZeroMq管道字符串。
However, If you want to get serialiazation from a library use protobuf it will generate classes for Python and C++. You use the SerializeToString() and ParseFromString() functions on either end, and then pipe the strings via ZeroMq.
问题解决,因为我怀疑任何其他解决方案更快,
Problem solved, as I doubt any other solution is faster, and neither will any other solution be as easy to wire-up and simple to understand.
如果想对rpc使用特定的系统原语,如Windows和Unix上的命名管道Unix上的域套接字,那么您应该查看 Boost :: ASIO 。然而,除非你有(a)网络背景,(b)非常好地了解C ++,这将是非常耗时的
If want to use specific system primitives for rpc such as named pipes on Windows and Unix Domain Sockets on unix then you should look at Boost::ASIO. However, unless you have (a) a networking background, and (b) a very good understanding of C++, this will be very time consuming
这篇关于C ++和Python之间的简单IPC(跨平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!