Making a C++ program work as a C++ extension module 
Author Message
 Making a C++ program work as a C++ extension module

I have a C++ program of mine that had data I wanted to share with some
of my python code.  As a result I decided to make the C++ program a
thread within my Python code and run it from within Python.  What I did
is I wrote a C++ extension module that goes in and starts up a (C++)
thread on top of which my program runs.  I can't seem to get the program
to work correctly however.  The program simply reads and writes to a USB
device.  It runs fine when I compile and run it by itself (it's
literally the same code, all i did was throw a main in the code that
calls that function that starts the separate thread, so it still runs as
a separate thread).  When run from Python, it runs, but the data I get
back from the USB is all jumbled (the data seems to be there, but it is
out of order, even though i only call fread once per set of data).  When
run from C++ it runs fine.  For the life of me, I don't know what it
could be.  All the program does is fread and fwrite to a USB device on
linux.  Somehow the data is getting screwed up, but I don't have a clue
as to how.  Does anyone have any ideas....I've been stuck on this for a
couple of days, and I just can't seem to come up with what the problem
could be.  The only difference between the two programs that I can
discern is that when run from Python, it shares the same Python's memory
space, as well as all process shared information.

TIA,

Dan Parks



Wed, 02 Feb 2005 04:23:47 GMT  
 Making a C++ program work as a C++ extension module

Quote:
> I have a C++ program of mine that had data I wanted to share with some
> of my Python code.  As a result I decided to make the C++ program a
> thread within my Python code and run it from within Python.  What I did
> is I wrote a C++ extension module that goes in and starts up a (C++)
> thread on top of which my program runs.  I can't seem to get the program
> to work correctly however.  The program simply reads and writes to a USB
> device.  It runs fine when I compile and run it by itself (it's
> literally the same code, all i did was throw a main in the code that
> calls that function that starts the separate thread, so it still runs as
> a separate thread).  When run from Python, it runs, but the data I get
> back from the USB is all jumbled (the data seems to be there, but it is
> out of order, even though i only call fread once per set of data).  When
> run from C++ it runs fine.  For the life of me, I don't know what it
> could be.  All the program does is fread and fwrite to a USB device on
> linux.  Somehow the data is getting screwed up, but I don't have a clue
> as to how.  Does anyone have any ideas....I've been stuck on this for a
> couple of days, and I just can't seem to come up with what the problem
> could be.  The only difference between the two programs that I can
> discern is that when run from Python, it shares the same Python's memory
> space, as well as all process shared information.

> TIA,

> Dan Parks

Try writing the data out to a file in the C++ code just before it exits. Is
it still good? If you timestamp the data when writing it out from C++ and
Python, is the Python code accessing a buffer before the C++ code has
finished?

If it is, but as soon as you print it from Python it's 'bad', are you sure
you're printing what the C++ code returned?

Is what the C++ code returned still on the heap or was it destroyed when the
code exited?

How's the boundary between C++ and Python where you are passing the data
back?

Dilton



Wed, 02 Feb 2005 10:38:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Making C++ loadable modules work

2. Making C++ loadable modules work

3. Making a python extension in c++

4. Making python module using Borland C++ 5

5. extension module for C++ library?

6. Python extension to a C++ module...

7. C++ extension module crashes on Solaris

8. C++ Builder and extension modules

9. C++ calling a Python extension module

10. C++ extension modules on NT

11. AIX and C++ shared extension modules

12. problem building C++ extension module using distutils

 

 
Powered by phpBB® Forum Software