Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38220

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

From Terry Reedy <tjreedy@udel.edu>
Subject Re: real-time monitoring of propriety system: embedding python in C or embedding C in python?
Date 2013-02-05 14:33 -0500
References <e13b91a6-e409-440a-ac96-91df67c832c4@googlegroups.com> <XnsA15E9C9C99379duncanbooth@127.0.0.1>
Newsgroups comp.lang.python
Message-ID <mailman.1382.1360092837.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 2/5/2013 10:23 AM, Duncan Booth wrote:
> Bas <wegwerp@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

real-time monitoring of propriety system: embedding python in C or embedding C in python? Bas <wegwerp@gmail.com> - 2013-02-05 07:10 -0800
  Re: real-time monitoring of propriety system: embedding python in C or embedding C in python? Duncan Booth <duncan.booth@invalid.invalid> - 2013-02-05 15:23 +0000
    Re: real-time monitoring of propriety system: embedding python in C or embedding C in python? Terry Reedy <tjreedy@udel.edu> - 2013-02-05 14:33 -0500
  Re: real-time monitoring of propriety system: embedding python in C or embedding C in python? rusi <rustompmody@gmail.com> - 2013-02-05 08:14 -0800
  Re: real-time monitoring of propriety system: embedding python in C or embedding C in python? Stefan Behnel <stefan_ml@behnel.de> - 2013-02-05 19:19 +0100

csiph-web