Python/C++ Data Exchange¶
Location: example/py-cpp-exchange/dragon
This example shows a Python driver launching a compiled C++ application and exchanging data with it through a shared Dragon DDict, using the radex Python client on one side and the C++ client on the other.
How It Works¶
- Creates a Dragon
DDictand serializes it. - Launches the compiled example binary (
dragon-cpp-with-py, frominstall/bin/examples) as a DragonProcess, passing the serializedDDictthrough theSERIALIZED_DDICTenvironment variable. - Creates a radex
DragonClientattached to the sameDDict. - Writes values from Python that the C++ application reads, and vice versa.
from radex.clients.core import DragonClient as Client
from radex.handles.handles import IncomingHandle, OutgoingHandle
client = Client(serial_dd, 5)
client.put_scalar(OutgoingHandle("py-int"), 123)
The C++ side (built from app.cpp) attaches its own client to the same serialized DDict descriptor and reads/writes using the equivalent C++ API (see C++ Data Exchange).