making my extensions work together

Stefan Behnel stefan_ml at behnel.de
Thu Aug 4 08:00:37 CEST 2011


Mathew, 04.08.2011 03:19:
> This isn't exactly a Python question but maybe someone here has run into
> this.
>
> I have 2 extensions

With "extensions", I assume you mean extension modules for the CPython 
runtime that are written in C? It would help if you were more specific in 
your problem description.


> and they both access a function in a (static) library.

It would help if you mentioned the names of the modules (or packages) and 
of the external library.


> The function maintains state information using a static variable.

That's bad design, but it happens.


> This doesn't work. When one of my extensions changes the variable value, the
> other extension does not see the change.

Are the two modules linked in any way or are they just arbitrary modules 
that happen to be installed at the same time, trying to use the same 
external C library?

If the former, consider letting them communicate with each other by making 
one depend on the other. If you control the source code, you may also 
consider wrapping the library only once and reusing that from the two 
modules. Or, just move the configuration part into a separate module and 
have both depend on that. Or, try to dump the dependency on the static 
variable.

If the latter, then, well, it depends on several environmental factors that 
you left out in your question.


> Would it work if I made my library dynamic?

That's usually a good idea, but it's unlikely to help in this specific case.


> This is on Windows XP compiling with MSVC 2008.

Others will know more here.

Stefan




More information about the Python-list mailing list