Quick question about threads and interpreters.

Chris Angelico rosuav at gmail.com
Mon Aug 1 07:57:41 CEST 2011

On Mon, Aug 1, 2011 at 6:04 AM, Ira Gray <tkjthingone at gmail.com> wrote:
> I come along, write a .DLL and throw it into the program. My .dll has its
> own thread (right?),

Not unless you actually create one. A DLL is simply a puddle of code;
the application calls your code, you do whatever you do, you return.
At no time will this start another thread, unless you explicitly do

I think the easiest way to do what you're talking about is to keep it
all on the same thread, and then call back into Python. Use the same
global and local dictionaries, and then the Python namespace will be
common across both your original code and the code your DLL is
invoking - which will allow you to call that "existing functionality"
you referred to.

You will have to be careful to ensure that your DLL calls into the
exact same Python library that the main application is. This might be
a bit tricky, if you're not 100% sure of where your DLL is going to be
called from. It might be easier and safer to have your parent program
actually provide a function pointer to the DLL, which the DLL can then
use to call on Python; that way, there's no direct linkage from your
DLL to the Python library.

Chris Angelico

More information about the Python-list mailing list