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

Daniel Parks Dan.Parks at
Fri Aug 16 22:23:47 CEST 2002

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.


Dan Parks

More information about the Python-list mailing list