real-time monitoring of propriety system: embedding python in C or embedding C in python?

Terry Reedy tjreedy at udel.edu
Tue Feb 5 14:33:28 EST 2013


On 2/5/2013 10:23 AM, Duncan Booth wrote:
> Bas <wegwerp at gmail.com> wrote:
>
>> A) Implement the main program in C. In a loop, get a chunk of data
>> using direct call of C functions, convert data to python variables and
>> call an embedded python interpreter that runs one iteration of the
>> user's algorithm. When the script finishes, you read some variables
>> from the interpreter and then call some other C-function to write the
>> results.
>>
>> B) Implement the main loop in python. At the beginning of the loop,
>> you call an embedded C function to get new data (using ctypes?), make
>> the result readable from python (memoryview?), do the user's
>> calculation and finally call another C function to write the result.
>>
>> Are there any advantages for using one method over the other? Note
>> that I have more experience with python than with C.
>
> Option B sounds like it makes your life simpler. Just turn the external
> code into a library, use ctypes to call the library and you're done. That
> also means reading command line arguments and/or config files can be done
> in Python and keep the C code simpler.

This is exactly how I would start. If this is not fast enough for 
production, Cython may help.

-- 
Terry Jan Reedy




More information about the Python-list mailing list