Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10833 > unrolled thread

making my extensions work together

Started by"Mathew" <myeates@jpl.nasa.gov>
First post2011-08-03 18:19 -0700
Last post2011-08-04 07:04 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  making my extensions work together "Mathew" <myeates@jpl.nasa.gov> - 2011-08-03 18:19 -0700
    Re: making my extensions work together John Gordon <gordon@panix.com> - 2011-08-04 03:22 +0000
    Re: making my extensions work together Stefan Behnel <stefan_ml@behnel.de> - 2011-08-04 08:00 +0200
    Re: making my extensions work together Chris Angelico <rosuav@gmail.com> - 2011-08-04 08:08 +0100
      Re: making my extensions work together "Mathew" <myeates@jpl.nasa.gov> - 2011-08-04 06:48 -0700
    Re: making my extensions work together "Mathew" <myeates@jpl.nasa.gov> - 2011-08-04 07:04 -0700

#10833 — making my extensions work together

From"Mathew" <myeates@jpl.nasa.gov>
Date2011-08-03 18:19 -0700
Subjectmaking my extensions work together
Message-ID<j1cs2t$j2f$1@news.jpl.nasa.gov>
This isn't exactly a Python question but maybe someone here has run into 
this.

I have 2 extensions and they both access a function in a (static) library. 
The function maintains state information using a static variable.

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

Would it work if I made my library dynamic?

This is on Windows XP compiling with MSVC 2008.

-Mathew 

[toc] | [next] | [standalone]


#10835

FromJohn Gordon <gordon@panix.com>
Date2011-08-04 03:22 +0000
Message-ID<j1d39m$p3l$1@reader1.panix.com>
In reply to#10833
In <j1cs2t$j2f$1@news.jpl.nasa.gov> "Mathew" <myeates@jpl.nasa.gov> writes:

> This isn't exactly a Python question but maybe someone here has run into 
> this.

> I have 2 extensions and they both access a function in a (static) library. 
> The function maintains state information using a static variable.

I'm not sure what you mean by "extension", but it might not be relevant.

Are these extensions, whatever they may be, part of the same program?
Or are they separate?

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

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#10842

FromStefan Behnel <stefan_ml@behnel.de>
Date2011-08-04 08:00 +0200
Message-ID<mailman.1877.1312437652.1164.python-list@python.org>
In reply to#10833
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

[toc] | [prev] | [next] | [standalone]


#10845

FromChris Angelico <rosuav@gmail.com>
Date2011-08-04 08:08 +0100
Message-ID<mailman.1880.1312441742.1164.python-list@python.org>
In reply to#10833
On Thu, Aug 4, 2011 at 2:19 AM, Mathew <myeates@jpl.nasa.gov> wrote:
> I have 2 extensions and they both access a function in a (static) library.
> The function maintains state information using a static variable.

If your extensions are DLLs and they're both linking to the same
static library, you should have two independent copies of that library
- which would mean they don't interfere with one another. That's why
the other extension doesn't see the change, and normally this is the
correct and desired behaviour.

Having the two be aware of each other is potentially very messy. As
Stefan suggested, making one depend on the other would be a lot
simpler. Alternatively, there may be ways to have the two extensions
share data through Python itself. What are you looking to accomplish?

ChrisA

[toc] | [prev] | [next] | [standalone]


#10861

From"Mathew" <myeates@jpl.nasa.gov>
Date2011-08-04 06:48 -0700
Message-ID<j1e7uv$1md$1@news.jpl.nasa.gov>
In reply to#10845
more info.  I have a large 3rd party library with a function that looks like 
this
void dumbfunc() {
static int statevar=0;
++statevar;
if (startvar ==3) printf("I have been called 3 times\n");
}

and I have 2 extensions, foo,py goo.py,created with SWIG, and the both make 
calls to dumbfunc. In creating the extensions, I linked to the 3rd party 
library.

The behavior I want to see is
>foo.dumbfunc()
>goo.dumbfunc()
>goo.dumbfunc()
I have been called 3 times


"Chris Angelico" <rosuav@gmail.com> wrote in message 
news:mailman.1880.1312441742.1164.python-list@python.org...
> On Thu, Aug 4, 2011 at 2:19 AM, Mathew <myeates@jpl.nasa.gov> wrote:
>> I have 2 extensions and they both access a function in a (static) 
>> library.
>> The function maintains state information using a static variable.
>
> If your extensions are DLLs and they're both linking to the same
> static library, you should have two independent copies of that library
> - which would mean they don't interfere with one another. That's why
> the other extension doesn't see the change, and normally this is the
> correct and desired behaviour.
>
> Having the two be aware of each other is potentially very messy. As
> Stefan suggested, making one depend on the other would be a lot
> simpler. Alternatively, there may be ways to have the two extensions
> share data through Python itself. What are you looking to accomplish?
>
> ChrisA 

[toc] | [prev] | [next] | [standalone]


#10862

From"Mathew" <myeates@jpl.nasa.gov>
Date2011-08-04 07:04 -0700
Message-ID<j1e8tp$1uc$1@news.jpl.nasa.gov>
In reply to#10833
okay. It worked to make my 3'rd party library dynamic. Hopefully this will 
help someone else in the future.


"Mathew" <myeates@jpl.nasa.gov> wrote in message 
news:j1cs2t$j2f$1@news.jpl.nasa.gov...
> This isn't exactly a Python question but maybe someone here has run into 
> this.
>
> I have 2 extensions and they both access a function in a (static) library. 
> The function maintains state information using a static variable.
>
> This doesn't work. When one of my extensions changes the variable value, 
> the other extension does not see the change.
>
> Would it work if I made my library dynamic?
>
> This is on Windows XP compiling with MSVC 2008.
>
> -Mathew
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web