Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple IPC between C++ and Python (cross platform)

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.

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

What are my options?

Thanks

like image 582
Lee Treveil Avatar asked Aug 02 '11 16:08

Lee Treveil


2 Answers

zeromq -- and nothing else. encode the messages as strings.

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.

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

like image 65
Hassan Syed Avatar answered Oct 03 '22 00:10

Hassan Syed


Use zeromq, it's about as simple as you can get.

like image 39
zeekay Avatar answered Oct 03 '22 02:10

zeekay