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

Dilton McGowan II diltonm at pacbell.net
Fri Aug 16 22:38:01 EDT 2002


"Daniel Parks" <Dan.Parks at CAMotion.com> wrote in message
news:mailman.1029529411.24277.python-list at python.org...
> 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





More information about the Python-list mailing list