2
$\begingroup$

I'm running Python code to receive live data stream through web-socket and storing it in the shared memory as the following;

Python Code

.
.
.
import sysv_ipc, json
queueNumber = 1111
try:
    msq = sysv_ipc.MessageQueue(queueNumber, sysv_ipc.IPC_CREX, )
except Exception as e:
    print(e)
    msq = sysv_ipc.MessageQueue(queueNumber)

.
.
.
''' code to receive data from web-socket'''
.
.
.
                a = json.dumps(data)
                msq.send(a.encode())

I want to access this data, stored in the shared memory, from Mathematica, perform the computation and put the result back into the shared memory so that, it can be accessed by Python.

Can anyone suggest me, how can I access the data in the shared memory from Mathematica?

$\endgroup$
5
  • 1
    $\begingroup$ I'm not aware of a built-in solution. But I recently finished shared_memory project letting people share data between Python - Julia - Matlab - Java - Mathematica using shared memory. You can share a numeric array (signed and unsigned 8, 16, 32, 64 bits + float, double with complex 64, 128) with any dimensions + string between them (with some limitations in Java interface). $\endgroup$
    – Ben Izd
    Dec 5, 2022 at 15:02
  • $\begingroup$ @BenIzd: Can you please provide me the .c file. My requirement is that I need to share a struct object between Python and Mathematica. $\endgroup$
    – csk 7
    Dec 5, 2022 at 16:42
  • $\begingroup$ The project is built on top of Rust. No .c files exist but you can use the native library and header file to call functions in your language of choice. I don't have information about your struct or requirements, but based on your code, just share the JSON dump as a string. You don't have to do anything other than importing the files and calling the functions like the example shown in the repository. $\endgroup$
    – Ben Izd
    Dec 5, 2022 at 17:04
  • $\begingroup$ @BenIzd: Could you please provide .so file for linux, instead of the .dll file? $\endgroup$
    – csk 7
    Dec 5, 2022 at 17:54
  • $\begingroup$ Unfortunately, I don't have access to Linux to build the .so file but the build process for Rust is relatively easy. Install Rust and run cargo build --release in the rust folder. It will download the dependencies and build a .so file (assuming you're on Linux). $\endgroup$
    – Ben Izd
    Dec 5, 2022 at 18:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.