By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

Data [shared] between python and c program

P: 14
Hey

Im having a problem with data communication between a python program and a c program.

The c program calculates the data, so it a kind of a solver.
Data variables should be chanced in real time from the python program.

A solution could be writing to shared memory. But how can i write an array to shared memory?
Or is there anybody there have another idea`?
Jun 4 '07 #1
Share this Question
Share on Google+
3 Replies


bartonc
Expert 5K+
P: 6,596
Hey

Im having a problem with data communication between a python program and a c program.

The c program calculates the data, so it a kind of a solver.
Data variables should be chanced in real time from the python program.

A solution could be writing to shared memory. But how can i write an array to shared memory?
Or is there anybody there have another idea`?
Because most data objects in memory are relocatable, it's kind of scary to implement memory shares. The C part of the system would need to allocate the memory and make sure that it doesn't get relocated and return it to python as a PyObject.

The really tricky part would be trying to syncronize the solver with the changes to the data.

I'm going to ponder on this problem. It is doable, but your model seem a bit out of whack.

For a quick implementation that didn't need super high performance, I'd use a DB and write SQL queries on both sides of the problem space.
Jun 4 '07 #2

Motoma
Expert 2.5K+
P: 3,235
Hey

Im having a problem with data communication between a python program and a c program.

The c program calculates the data, so it a kind of a solver.
Data variables should be chanced in real time from the python program.

A solution could be writing to shared memory. But how can i write an array to shared memory?
Or is there anybody there have another idea`?
Have one of the programs call the other?
Jun 4 '07 #3

bartonc
Expert 5K+
P: 6,596
Have one of the programs call the other?
Yep. That's the normal way to do it. I like to call DLL functions from Python. But if the process of "solving" is a long running operation, then you want a thread that's already running (or started by the ready-state of the data) which has some way of signaling that it has completed its task (hence the shared memory idea).
Jun 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.