Sharing information between a python code and c++ code (IPC) -


i have 2 code bases, 1 in python, 1 in c++. want share real time data between them. trying evaluate option work best specific use case:

  • many small data updates c++ program python program
  • they both run on same machine
  • reliability important
  • low latency nice have

i can see few options:

  • one process writes flat file, other process reads it. non scalable, slow , i/o error prone.
  • one process writes database, other process reads it. makes more scalable, less error prone, still slow.
  • embed python program c++ 1 or other way round. rejected solution because both code bases reasonably complex, , prefered keep them separated maintainability reasons.
  • i use sockets in both programs, , send messages directly. seems reasonable approach, not leverage fact on same machine (it optimized using local host destination, still feels cumbersome).
  • use shared memory. far think satisfying solution have found, has drawback of being more complex implement.

are there other solutions should consider?

first of all, question highly opinion-based!

the cleanest way use them in same process , them communicate directly. complexity implement proper api , c++ -> python calls. drawbacks maintainability noted , potentially lower robustness (both crash together, not problem in cases) , lower flexibility (are sure you'll never need run them on different machines?). extensibility best it's simple add more communication or change existing. can reconsider maintainability point. can python app used w/o c++ counterpart? if not wouldn't worry maintainability much.

then shared memory next choice better maintainability same other drawbacks. extensibility little bit worse still not bad. can complicated, don't know python support shared memory operation, c++ can have @ boost.interprocess. main question i'd check first synchronisation between processes.

then, network communication. lots of choices here, simplest possible binary protocol implemented on socket level higher-level options mentioned in comments. depends how complex c++ <-> python communication , can in future. approach can more complicated implement, can require 3rd-party libraries once done it's extensible , flexible. 3rd-party libraries based on code generation (thrift, protobuf) doesn't simplify build process.

i wouldn't consider file system or database case.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -