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


Groups > comp.lang.python > #38200

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

From Duncan Booth <duncan.booth@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: real-time monitoring of propriety system: embedding python in C or embedding C in python?
Date 2013-02-05 15:23 +0000
Message-ID <XnsA15E9C9C99379duncanbooth@127.0.0.1> (permalink)
References <e13b91a6-e409-440a-ac96-91df67c832c4@googlegroups.com>

Show all headers | View raw


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.

Embedding Python isn't hard but it sounds more complex than needed here.

You can of course mix the two. If it's more convenient put the main loop in 
Python but use callbacks from the library to handle the values as they 
appear, but again that probably just complicates things.

-- 
Duncan Booth http://kupuguy.blogspot.com

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